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) {
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.
source
share