welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Friday, August 31, 2012

java.text.ParseException- Convert string to Date type in android

HI. I got this above error , when I try to convert string to date type format.
In my scenario   I get  the data in string variable then I need to convert the string to certain Date format.
For that I tried many ways to accomplish my needs but each try I got this below error..

java.text.ParseException: Unparseable date: "01-08-2012"

Finally my friend refer the code ,then I convert the string to my date format.
Requirement Format I need:
“02 Feb “I need to this type of Format
Before the start the process you need to import the below namespace….

import java.util.*;
import java.text.*;

This the code finally Work For me…………..
String strformat="MMM-dd";
String ddate="01-08-2012";//Date in string format
                     SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
                     java.util.Date date=sdf.parse(ddate);
                     sdf=new SimpleDateFormat("dd-MMM");//Format i need
                     Toast.makeText(this, sdf.format(date), Toast.LENGTH_LONG).show();
              catch(Exception ex){
                     Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();

Any Doubts please share with comments..
Happy Coding……….


Post a Comment