1

I want to parse a timestamp given in this format timestamp="2015-05-21 12:38:00Z" using the class SimpleDateFormat. The problem is the "Z" in the end of timestamp which specifies the time zone. Unfortunately

new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")

doesn't do the job. It throws me:

java.text.ParseException: Unparseable date: "2015-05-21 12:38:00Z"

If I use

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'")

the string can be parsed but the time zone "Z" is neglected.

How can that problem be solved?

principal-ideal-domain
  • 3,862
  • 6
  • 30
  • 66

1 Answers1

2

Just use X to indicate ISO 8601 time zone:

new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX").parse("2015-05-21 12:38:00Z")

Tarlog
  • 9,849
  • 2
  • 42
  • 66