18034727885
2026-06-26 253f680fb9666751e0f9a8e5e8f2f9e3eb1894e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.example.basecore.util
 
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*
 
/**
 * author: dai
 * date : 2019-11-23
 * desc:
 */
object DateUtils {
 
 
    @JvmStatic
    fun getCurrentDate(): String {
        val date = Date()
        return date.toString()
 
    }
    /**
     * 秒转时分秒
     */
    fun calDate(timeMs: Long): String {
        val seconds = timeMs % 60
        val minutes = timeMs / 60 % 60
        val hours = timeMs / 3600
        return Formatter().format("%02d:%02d:%02d", hours, minutes, seconds).toString()
    }
 
 
    @SuppressLint("SimpleDateFormat")
    @JvmStatic
    fun getCurDate(): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd")
        val date = Date(System.currentTimeMillis())
        return sdf.format(date)
    }
 
    fun getCurDate(str: String): Date {
        return getCurDate(str, "yyyy年MM月dd日")
    }
 
    fun getCurDate(str: String, format: String): Date {
        val sdf = SimpleDateFormat(format)
        return sdf.parse(str)
    }
 
    /**
     * 将日期转换为时间戳
     */
    fun dateToStamp(str: String): String {
        val simpleDateFormat =
            SimpleDateFormat("yyyy年MM月dd日  HH时mm分ss秒SSS毫秒")
        val date = simpleDateFormat.parse(str)
        return date.time.toString()
    }
 
    /**
     * 将时间戳转换为时间
     */
    fun stampToDate(s: String, format: String?): String? {
        val res: String
        val simpleDateFormat = SimpleDateFormat(format)
        val lt: String = s
        val date = Date(lt)
        res = simpleDateFormat.format(date)
        return res
    }
 
 
    @SuppressLint("SimpleDateFormat")
    fun stampToDate(s: Long): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd")
        val date = Date(s)
        return sdf.format(date)
    }
 
 
    fun getCurrentTime(): String {
        val sdf = SimpleDateFormat("HH:mm:ss")
        val date = Date(System.currentTimeMillis())
        return sdf.format(date)
    }
}