How to get current date in UTC zone as long value in java 8

secret super star :

How to achieve the following in java 8 date time API

long currentDate = Date.UTC(date.getYear(), date.getMonth(), date.getDate(), 0, 0, 0);
System.out.println(currentDate);

The above code returned

1573171200000

I have tried following

ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneOffset.UTC);
System.out.println(zonedDateTime.toEpochSecond());

returned

1573212520

Andy Turner :

Get the LocalDate for today, convert it to a ZonedDateTime at the start of the day, then convert to Instant and get the epoch millis:

LocalDate.now().atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=323788&siteId=1
Recommended