Kotlin Useful Java Time Ktx

Dec 17, 2021
fun LocalDateTime.toMillis(zone: ZoneId = ZoneId.systemDefault()) = atZone(zone)?.toInstant()?.toEpochMilli()fun LocalDateTime.toDate(zone: ZoneId = ZoneId.systemDefault()) = Date.from(atZone(zone)?.toInstant())fun LocalDate.atEndOfDay() = atTime(LocalTime.MAX);

If you are dealing with Firestore Timestamp

fun Timestamp.toLocalDateTime(zone: ZoneId = ZoneId.systemDefault()) = LocalDateTime.ofInstant(    Instant.ofEpochMilli(seconds * 1000 + nanoseconds / 1000000), zone)fun LocalDateTime.toTimestamp(zone: ZoneId = ZoneId.systemDefault()): Timestamp {    return Timestamp(toDate(zone))}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.