Parsing date from string to long gives wrong result

I have simple code, maybe the problem depends on the given format string or on the time zone. So here is the code:

public static void main(String[] args) {
    SimpleDateFormat df = new SimpleDateFormat("HH:mm");
    try {
        Date added = df.parse("00:00");
        System.out.println(added);
        System.out.println(added.getTime());
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Result: Thu Jan 01 00:00:00 EET 1970 -10800000 → should be 0, because we give 00:00 hours, and the remaining time elements remain by default.

// Change

Yes, the problem is with the time zone to fix this using df.setTimeZone (TimeZone.getTimeZone ("UTC")); before parsing.

+5
source share
3 answers

10800000 3 ( ), , EET UTC ( 2 , , DST - ).

, , , .

+2

EET. 1 1970 00: 00: 00.000 UTC

+2

, , Date , DateFormat API ( SimpleDateFormat):

Date 1 1970 , 00:00:00 .

0

All Articles