-4

I have string like below and I need to convert this as a date in java

"Tue Sep 30 00:00:00 GMT+05:30 2014"

This is a string representation of the java date object. I get it as a string where I need to parse it like "30 Sep 2014"

I thought if I could get this as a date object I can get whatever format I want using simpledateformat. But the problem is how do I get the date Object from this string

Gautam Savaliya
  • 1,265
  • 2
  • 18
  • 31
seeker
  • 67
  • 11

4 Answers4

1

The format you're looking for is this:

SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy");

You can check all the valid formats here http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

ares
  • 4,113
  • 5
  • 33
  • 61
1

You can also use SimpleDateFomrat to parse the string into date:

String s = "Tue Sep 30 00:00:00 GMT+05:30 2014";
SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
System.out.println(df.parse(s));
Jens
  • 63,364
  • 15
  • 92
  • 104
0
public static Date convertDate(final String dateValue) {
    final SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
    Date date = null;
    try {
        date = format.parse(dateValue);
        return date;
    } catch (final ParseException e) {
        LOG.error(e.getMessage(), e);
        return null;
    }
}
phani sekhar
  • 107
  • 1
  • 1
  • 13
-1

the java 8 version... and you will find much more entries already exist in stackoverflow.

Community
  • 1
  • 1
user2504380
  • 535
  • 3
  • 12