Skip to content Skip to sidebar Skip to footer

Convert String To Date Android

I'm trying to convert a String that represents a date stored in SQLITE. The date was stored into sqlite as follows: Date date; date.toString(); According with Java documentation,

Solution 1:

try this code

StringdateString="here your date";
SimpleDateFormatdateFormat=newSimpleDateFormat("dd/MM/yyyy");
DateconvertedDate=newDate();
try {
    convertedDate = dateFormat.parse(dateString);
} catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
System.out.println(convertedDate);

Solution 2:

Try this:

Stringw="Mon Jan 20 18:26:25 BRT 2014";
SimpleDateFormatpre=newSimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
SimpleDateFormatsdf=newSimpleDateFormat("dd/MM/yyyy");
try{
    Datedate= pre.parse(w);
    System.out.println(sdf.format(date));
}catch(Exception e){
    e.printStackTrace();
}

Output:

20/01/2014

Solution 3:

Formatter for storing and restoring data value in format dd/MM/yyyy

SimpleDateFormatsimpleDateFormat=newSimpleDateFormat("dd/MM/yyyy");

Storing data

StringdataAsString= simpleDateFormat.format(date); // 20/01/2014

Restoring data

Datedata= simpleDateFormat.parse(dataAsString);

Post a Comment for "Convert String To Date Android"