-
Notifications
You must be signed in to change notification settings - Fork 1
/
Date.kt
57 lines (47 loc) · 1.52 KB
/
Date.kt
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
fun Date.getCurrentTimeString() : String {
val timeFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
return timeFormat.format(this.time)
}
fun Date.getCurrentTimeHour() : Int {
return this.getCurrentTimeString().split(":")[0].toInt()
}
fun Date.getCurrentTimeMinutes() : Int {
return this.getCurrentTimeString().split(":")[1].toInt()
}
fun Date.getMonthNumber(): Int {
val dateFormat = SimpleDateFormat("MM", Locale.getDefault())
val mStr = dateFormat.format(this.time)
return Integer.parseInt(mStr)
}
fun Date.getCurrentDayString(): String {
val dateFormat = SimpleDateFormat("dd", Locale.getDefault())
return dateFormat.format(this.time)
}
/**
* Getting current weekday name string
*/
fun Date.getCurrentWeekdayString() : String {
val weekdayFormat = SimpleDateFormat("EEEE", Locale.getDefault())
return weekdayFormat.format(this.time)
}
fun Date.getCurrentDateString() : String {
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
return dateFormat.format(this.time)
}
fun Date.getCurrentDayAndMonthString(): String {
val dateFormat = SimpleDateFormat("d MMMM", Locale.getDefault())
return dateFormat.format(this.time)
}
fun Date.getCurrentYear() : String {
val dateFormat = SimpleDateFormat("yyyy", Locale.getDefault())
return dateFormat.format(this.time)
}
fun Date.getCurrentYearInt() : Int {
return Integer.parseInt(this.getCurrentYear())
}
/**
* Getting date from Unix time
*/
fun Long.extractDate() : Date {
return Date(this*1000L)
}