英文:
Kotlin: how to get the start time of a day and end time of a day?
问题
将Unix纪元开始的输入表示日期,需要将日期转换为同一日期的一天的开始时间和结束时间,有哪些在Kotlin中实现这个目标的可能选项?
英文:
My input is unix seconds from epoch, which represents the date, that I need to work with, I need to convert the date to start time of a day and end time of a day of the same date, what are possible options to do so in Kotlin?
答案1
得分: 2
你可以使用 LocalDate
轻松地实现这种行为,使用纪元时间
val localDate = Instant.ofEpochMilli(timeInEpoch).atZone(ZoneId.systemDefault()).toLocalDate()
val startDate = localDate.atStartOfDay() // (or) localDate.atTime(LocalTime.MIN)
val endDate = localDate.atTime(LocalTime.MAX)
英文:
You could use LocalDate
to easily achieve this behaviour using epoch
val localDate = Instant.ofEpochMilli(timeInEpoch).atZone(ZoneId.systemDefault()).toLocalDate()
val startDate = localDate.atStartOfDay() // (or) localDate.atTime(LocalTime.MIN)
val endDate = localDate.atTime(LocalTime.MAX)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论