Antoine Molinaro
Antoine Molinaro

Reputation: 13

Wrong hours converted to epoch time

I'm trying to convert a date with epoch time method.
with these code below

long epoch = 0;
try {
    epoch = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("12/11/2017 23:20:23")
            .getTime();
} catch (ParseException e) {
    e.printStackTrace();
}

It gives me the epoch time: 1513052423

Which once convert give: Tuesday 12 December 2017 04:20:23 and not 23:20:23 :/

Upvotes: 1

Views: 69

Answers (1)

GuessWho
GuessWho

Reputation: 672

According to documentation SimpleDateFormat is locale-sensitive. Please check or set your timezone

sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

Upvotes: 4

Related Questions