转载自:LocalDateTime To Timestamp Epoch Seconds And Milliseconds
Convert LocalDateTime
to seconds since January 1, 1970, 00:00:00 GMT
val now = LocalDateTime.now(ZoneOffset.UTC) // LocalDateTime to epoch seconds val seconds = now.atZone(ZoneOffset.UTC).toEpochSecond()) // Epoch seconds to LocalDateTime val newNow = LocalDateTime.ofInstant(Instant.ofEpochSecond(seconds), ZoneOffset.UTC)
Convert LocalDateTime
to milliseconds since January 1, 1970, 00:00:00 GMT
// LocalDateTime to epoch milliseconds val milliseconds = now.atZone(ZoneOffset.UTC)?.toInstant()?.toEpochMilli() // epoch milliseconds to LocalDateTime val newNow = LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), ZoneOffset.UTC)
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。