Mark Mark - 10 months ago 75
Java Question

How to get UTC+0 date in java8?

I have problems with Date class in Java. Date class returns local machine date but i need UTC-0.

I have googled and found great solution for javascript but for java nothing usefull.

How to get UTC+0 date in Java 8?


With Java 8 you can write:

ZonedDateTime utc =;

To answer your comment, you can then convert it to a Date (unless you depend on legacy code I don't see any reason why) or to millis since the epochs:

Date date = Date.from(utc.toInstant());
long epochMillis = utc.toEpochSecond() * 1000;