Home > Mobile >  Scala - How to obtain UTC at Midnight Timestamp with java.time.Instant
Scala - How to obtain UTC at Midnight Timestamp with java.time.Instant

Time:10-21

Scala - How to obtain UTC at Midnight Timestamp with java.time.Instant

I am trying to get UTC at Midnight Timestamp in format Example if today were Feb 10 2017, then correct date: Fri Feb 10 00:00:00 UTC 2017 which is equal to timestamp: 1486684800000 (I want for current date and time).

I tried

Instant.now
Instant.now.getEpochSecond to pass in Json it end up in error

Error :

"statusCode":400,"titleMessage":"Value not allowed","userMessage":"The date with time stamp 2,022 is not in UTC at midnight

Please suggest a solution

CodePudding user response:

Truncate

You can lop off the less significant parts of a date-time value.

In Java syntax:

Instant
.now()
.truncatedTo( ChronoUnit.DAYS )
.toEpochMilli()
  • Related