docs: 添加管理平台标准加密算法 Kotlin 参考实现

This commit is contained in:
2026-03-06 15:34:04 +08:00
parent 2651ec0835
commit 4d64cfb93d
12 changed files with 935 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package top.tangyh.lamp.filing.utils
import java.text.SimpleDateFormat
import java.util.*
class DateUtil {
companion object {
// 获取当前时间戳
fun getCurrentTimestamp(): Long {
return System.currentTimeMillis()
}
// 格式化日期
fun formatDate(date: Date, format: String = "yyyy-MM-dd HH:mm:ss"): String {
val sdf = SimpleDateFormat(format)
return sdf.format(date)
}
// 解析日期字符串
fun parseDate(dateString: String, format: String = "yyyy-MM-dd HH:mm:ss"): Date? {
val sdf = SimpleDateFormat(format)
return try {
sdf.parse(dateString)
} catch (e: Exception) {
null
}
}
// 计算两个日期之间的天数差
fun getDaysBetweenDates(date1: Date, date2: Date): Long {
val diff = Math.abs(date1.time - date2.time)
return diff / (24 * 60 * 60 * 1000)
}
// 获取当前时间并格式化为 yyyy-MM-dd_HH-mm-ss
fun getCurrentFormattedTime(format: String = "yyyy-MM-dd_HH-mm-ss"): String {
val sdf = SimpleDateFormat(format)
return sdf.format(Date())
}
}
}