1

I am seeing a string as Wed Apr 27 00:00:00 GMT-700 1988 and to convert it to date I did

Date dateOfBirth = new Date(bean.getUserProfileBean().getDateOfBirth());

This fails and I am not sure why. Any idea if it is specific to GAE?

Vik
  • 8,721
  • 27
  • 83
  • 168

4 Answers4

1

The date Wed Apr 27 00:00:00 GMT-700 1988 is not in a format that Java can parse out of the box. Specifically, the timezone GMT-700 part is not parsable by any library that I know of.

This format is not any of the standard timezone formats: general timezone, RFC822 or ISO8601.

You will need to write your own parser for that.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
0

Date has empty constructor or Date(long)

If you want to get date from String, you need to use SimpleDateFormat

BobTheBuilder
  • 18,858
  • 6
  • 40
  • 61
0

Try:

stirng strDate = bean.getUserProfileBean().getDateOfBirth();
Date date = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy",
  Locale.ENGLISH).parse(strDate );

See this answer

Alternatively you can try to use the DateTimeFormatter of Joda-Time, although you may encounter problems with the 'z' for timezone names whih is conventional:

stirng strDate = bean.getUserProfileBean().getDateOfBirth();
DateTimeFormatter dtf = DateTimeFormat.forPattern("EEE MMM d HH:mm:ss z yyyy");
dtf.parseDateTime(strDate);
Community
  • 1
  • 1
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
0

to parse -700 the required format was Z,ZZ

Vik
  • 8,721
  • 27
  • 83
  • 168