File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed
src/main/java/com/catchpig/utils/ext Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 33### v1.2.3
44
55+ 升级刷新库版本
6+ + 增加毫秒数转字符串的扩展方法
67
78### v1.2.2
89
Original file line number Diff line number Diff line change 3535
3636## DateExt
3737
38+ + Long.format - 时间戳转字符串
3839+ String.date - 字符串转时间Date
3940+ Date.format - 时间Date转字符串
4041+ Date.calendar - Date转Calendar
Original file line number Diff line number Diff line change 11package com.catchpig.utils.ext
22
33import java.text.SimpleDateFormat
4- import java.util.*
4+ import java.util.Calendar
5+ import java.util.Date
56
67const val DATE_FORMAT = " yyyy-MM-dd HH:mm:ss"
8+
9+ /* *
10+ * 毫秒数转化为时间字符串
11+ * @receiver Long
12+ * @param format String
13+ * @return String
14+ */
15+ fun Long.format (format : String = DATE_FORMAT ): String {
16+ return Date (this ).format(format)
17+ }
18+
719/* *
820 * 字符串转化为时间
921 */
10- fun String.date (format : String = DATE_FORMAT ):Date {
22+ fun String.date (format : String = DATE_FORMAT ): Date {
1123 val dateFormat = SimpleDateFormat (format)
1224 return dateFormat.parse(this )!!
1325}
@@ -22,7 +34,7 @@ fun Date.format(format: String = DATE_FORMAT): String {
2234 return dateFormat.format(this )
2335}
2436
25- fun Date.calendar ():Calendar {
37+ fun Date.calendar (): Calendar {
2638 val calendar = Calendar .getInstance()
2739 calendar.time = this
2840 return calendar
@@ -31,7 +43,7 @@ fun Date.calendar():Calendar{
3143/* *
3244 * 获取年
3345 */
34- fun Date.year ():Int {
46+ fun Date.year (): Int {
3547 return calendar().year()
3648}
3749
@@ -59,13 +71,13 @@ fun Date.hour(): Int {
5971/* *
6072 * 获取分钟数
6173 */
62- fun Date.minute ():Int {
74+ fun Date.minute (): Int {
6375 return calendar().minute()
6476}
6577
6678/* *
6779 * 获取秒数
6880 */
69- fun Date.second ():Int {
81+ fun Date.second (): Int {
7082 return calendar().second()
7183}
You can’t perform that action at this time.
0 commit comments