0

Here is what I am doing :

SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH);
Date dateFormat = parserSDF.parse("Mon Nov 07 00:00:00 CEST 2016");

dateFormat should then contain Mon Nov 07 00:00:00 CET 2016, but here is what I get when logging it :

Sun Nov 06 23:00:00 CET 2016

Why do I get this hour of difference?

Thank you.

Rob
  • 4,123
  • 3
  • 33
  • 53
  • 2
    CEST is one hour ahead of CET so they are the same time - the output is using your local settings. – assylias Apr 01 '16 at 09:24

4 Answers4

3

CEST stands for Central European Summer Time, which is the same as CET but with daylight saving time into effect. Use CET, like:

Date dateFormat = parserSDF.parse("Mon Nov 07 00:00:00 CET 2016");
dambros
  • 4,252
  • 1
  • 23
  • 39
2

CEST stands for Central European Summer Time which is 1 hour after CET, so result is correct.

So if you go with:

Date dateFormat = parserSDF.parse("Mon Nov 07 00:00:00 CET 2016");

you'll get expected result.

user987339
  • 10,519
  • 8
  • 40
  • 45
1

CEST = Central European Summer Time

Summer time is +1 hour to normal CET. In November Summer time usually isn't used.

OH GOD SPIDERS
  • 3,091
  • 2
  • 13
  • 16
1

the issue is probably a timezone issue:

SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH);
parserSDF.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateFormat = parserSDF.parse("Mon Nov 07 00:00:00 CEST 2016");

Set the timezone as shown above. The issue has been resolved here: Java SimpleDateFormat: an hour wrong

Community
  • 1
  • 1
ArnoldKem
  • 100
  • 2