javadatedatetimedatetime-format

SimpleDateFormat and TimeZone format


I am trying to make the SimpleDateFormat class to do what I need without success.

Here is the date format I need:

Fri 29 May 2015 10:22:30 GMT-0400 (Eastern Daylight Time)

Here is the closest format definition I was able to come with:

SimpleDateFormat("EEE dd MM yyyy HH:mm:ss Z (zzzz)", Locale.ENGLISH)

This will output:

Fri 29 May 2015 10:22:30 -0400 (Eastern Daylight Time)

Is there a formatting that can do what I need or do I have no other choice than manipulating the String to insert the missing GMT tag?


Solution

  • You can add the literal GMT surrounded by quotes:

    new SimpleDateFormat("EEE dd MM yyyy HH:mm:ss 'GMT'Z (zzzz)", Locale.ENGLISH);