Files
FancyBot/src/main/kotlin/cn/rtast/fancybot/util/misc/DateUtil.kt
T

26 lines
684 B
Kotlin
Raw Normal View History

2024-08-30 14:24:46 +08:00
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/29
*/
2024-10-09 13:06:43 +08:00
package cn.rtast.fancybot.util.misc
2024-08-30 14:24:46 +08:00
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
private val zoneId = ZoneId.of("Asia/Shanghai")
2024-08-30 14:24:46 +08:00
2024-09-02 11:30:58 +08:00
fun Long.isSameDay(timestamp2: Long): Boolean {
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
return date1 == date2
2024-08-30 14:24:46 +08:00
}
fun Long.convertToDate(): String {
val instant = Instant.ofEpochSecond(this)
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(zoneId)
return formatter.format(instant)
}