docs: 添加管理平台标准加密算法 Kotlin 参考实现
This commit is contained in:
42
docs/工具箱端-授权对接指南/utils/DateUtil.kt
Normal file
42
docs/工具箱端-授权对接指南/utils/DateUtil.kt
Normal 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user