How to get currentTimeMillis on K/N?
# kotlin-native
b
How to get currentTimeMillis on K/N?
a
macOS, linux
Copy code
val nowMilleeconds = memScoped {
        val timeVal = alloc<timeval>()
        gettimeofday(timeVal.ptr, null)
        val sec = timeVal.tv_sec
        val usec = timeVal.tv_usec
        (sec * 1_000L) + (usec / 1_000L)
    }
Windows
Copy code
val nowMilleeconds = memScoped {
        val timeVal = alloc<timeval>()
        mingw_gettimeofday(timeVal.ptr, null) // mingw: doesn't expose gettimeofday, but mingw_gettimeofday
        val sec = timeVal.tv_sec
        val usec = timeVal.tv_usec
        (sec * 1_000L) + (usec / 1_000L)
    }
b
Can't I just use
Copy code
kotlin.system.getTimeMillis()
Or is that not the same?
a
It’s not a “unixtime”
Copy code
only delta between two subsequent calls makes sense.
b
I see, how would I get that on IOS, then?
e
iOS is the same as macOS.
🎉 1