Hi, Anybody knows how to get millisecond at any ti...
# getting-started
x
Hi, Anybody knows how to get millisecond at any time I want(not current time), for example, if I wanna transform
2023-01-01
to milliseconds, what should I do? is there something like
Date(2023,1,1).getMillisecond()
?
c
Kotlinx datetime should be able to get you what you need. If you’re only targeting JVM, you can use Java’s LocalDate API directly (Kotlinx datetime is basically a wrapper over this API, with backports for non-JVM targets). You can also use the standard Java
LocalDate
APIs on Android, but you’ll need to enable desugaring
x
Hi, thanks a lot , finally I got a solution like
Copy code
val startTime = LocalDateTime.of(2023, 1, 1, 0, 0, 0).toEpochSecond(ZoneOffset.of("+08:00"))
which is inspired by your advice. You made my day!