Hello, how can I have the epoch millisecond of my ...
# multiplatform
r
Hello, how can I have the epoch millisecond of my time zone and not UTC with kotlinx-datetime ?
1
m
There is no such thing as “the epoch millisecond of my time zone and not UTC”. By definition the epoch milliseconds are always based on UTC time but you can derive your local date/time from that. https://en.wikipedia.org/wiki/Unix_time
👀 1
c
Please describe what you want to achieve exactly, #C01923PC6A0
r
I managed to succeed with
Copy code
fun Clock.System.nowTimeZone(
    timeZone: TimeZone = TimeZone.currentSystemDefault()
): Long {
    val now = now()
    val offset = now.offsetIn(timeZone)

    return now.toEpochMilliseconds() + offset.totalSeconds.times(1000)
}
c
I don't know what you want to do, but that's not equivalent to the number of seconds that happened since Jan 1st 1970 in your timezone. The offset is not constant over time; maybe that place has changed timezones since 1970 (happened to surprisingly more places than you'd think). Maybe you're currently in the summer time. It depends what you want to use that for. But if you have a counter that has counted the number of seconds, this is certainly not the value you'd expect.
Also, extension functions should be on
Clock
(not
Clock.System
) to make them easier to test.
thank you color 1
r
I want a timestamp of my zone. I know it's wrong. I'll changed soon to use ISO8601