Koziołek
Koziołek

Reputation: 2874

Java SimpleDateFormat and 19700101 conversion problem

i have a little problem with date conversion in java. When i put 19700101 to SimpleDateFormat and then call getTime i got -3600000. I write test:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = dateFormat.parse("19700101");
System.out.println(date.getTime());
System.out.println(dateFormat.format(new Date(0)));
System.out.println((new Date(0)).getTime());

Result should be:

0
19700101
0

but i got

-3600000
19700101
0

My question is why SimpleDateFormat return -3600000 (20Nov1969)? Where I can find information about formatting and conversion bugs?

Upvotes: 0

Views: 1993

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533660

Which time zone were you using? My guess is you were using GMT+1. Set the timezone to "GMT" and you should get the expected result.

You are using a default timezone like CEST (GMT+1). When it was 1970/01/01 00:00:00.000 CEST was 1969/12/31 23:00:00.000 GMT which is -1h from 1970/01/01 or -3600000 ms.

Upvotes: 8

Related Questions