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,998
  • 8
  • 36
  • 73

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
  • 10,024
  • 2
  • 43
  • 67