Search code examples
javasimpledateformatdatetime-parsing

Java date format - GMT +04:00


I have to parse the following date

Fri Sep 30 18:31:00 GMT+04:00 2016

and it is not working with the following pattern:

new SimpleDateFormat("EEE MMM dd HH:mm:ss z YYYY", Locale.ENGLISH);

I get the following date as output: Fri Jan 01 18:31:00 GMT+04:00 2016.

Could you please tell me what I am doing wrong?


Solution

  • It should be lower case "y":

    EEE MMM dd HH:mm:ss z yyyy
    

    Upper case "Y" means weekBasedYear:

    a date can be created from a week-based-year, week-of-year and day-of-week

    I guess mixing the week-based and absolute/era patterns just does not work well for parsing.