how to exclude the nano second from time?
# kotlinx-datetime
s
how to exclude the nano second from time?
j
Instant.fromEpochMilliseconds(timeWithNanos.toEpochMilliseconds())
s
i am using like this
Copy code
val timeNow: LocalTime = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).time
and i dont want the last . value
j
Copy code
val timeNow: LocalTime = Instant.fromEpochMilliseconds(
    Clock.System.now().toEpochMilliseconds()
).toLocalDateTime(TimeZone.currentSystemDefault()).time
s
it still shows me time in this format 125005.352 i just want 125003 or just 12:50 can be a good for me
j
Those are milliseconds. You can truncate any amount you want using the same pattern.
Copy code
val timeNow: LocalTime = Instant.fromEpochMilliseconds(
    Clock.System.now().epochSeconds
).toLocalDateTime(TimeZone.currentSystemDefault()).time
You can also truncate the string.
s
thanks you for the help @Jeff Lockhart i am going with this approach is this good or bad?
Copy code
val now : Instant = Clock.System.now()
 val currentTimeSelected: LocalTime = now.toLocalDateTime(TimeZone.currentSystemDefault()).time

val timeNow: String = "${currentTimeSelected.hour}:${currentTimeSelected.minute}:${currentTimeSelected.second}"
j
It depends on your use case. If that's the exact format you want and you don't care about localization, then it should work ok.
1
s
Thanks for the help and feedback @Jeff Lockhart you are awesome
👍🏼 1
😄 1