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
|
2024-10-11 17:12:50 +08:00
|
|
|
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
|
|
|
}
|
2024-10-11 17:12:50 +08:00
|
|
|
|
|
|
|
|
fun Long.convertToDate(): String {
|
|
|
|
|
val instant = Instant.ofEpochSecond(this)
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(zoneId)
|
|
|
|
|
return formatter.format(instant)
|
|
|
|
|
}
|