|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.xhly.corelib.utils
|
2
|
2
|
|
|
3
|
+import android.annotation.SuppressLint
|
3
|
4
|
import android.content.Context
|
4
|
5
|
import android.graphics.Bitmap
|
5
|
6
|
import android.graphics.BitmapFactory
|
|
@@ -8,6 +9,7 @@ import android.util.Base64
|
8
|
9
|
import java.lang.reflect.ParameterizedType
|
9
|
10
|
import java.text.DecimalFormat
|
10
|
11
|
import java.text.SimpleDateFormat
|
|
12
|
+import java.time.format.DateTimeFormatter
|
11
|
13
|
import java.util.Calendar
|
12
|
14
|
import java.util.Date
|
13
|
15
|
|
|
@@ -47,12 +49,12 @@ fun Long.toFormat(format: String = "yyyy-MM-dd HH:mm:ss"): String {
|
47
|
49
|
|
48
|
50
|
fun String.hourToCurrentDate(formatType: String = "HH:mm:ss"): Date {
|
49
|
51
|
try {
|
50
|
|
- var simpleDateFormat = SimpleDateFormat(formatType)
|
51
|
|
- var parse = simpleDateFormat.parse(this)
|
52
|
|
- var hours = parse.hours
|
53
|
|
- var minutes = parse.minutes
|
54
|
|
- var seconds = parse.seconds
|
55
|
|
- var calendar = Calendar.getInstance()
|
|
52
|
+ val simpleDateFormat = SimpleDateFormat(formatType)
|
|
53
|
+ val parse = simpleDateFormat.parse(this)
|
|
54
|
+ val hours = parse.hours
|
|
55
|
+ val minutes = parse.minutes
|
|
56
|
+ val seconds = parse.seconds
|
|
57
|
+ val calendar = Calendar.getInstance()
|
56
|
58
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH))
|
57
|
59
|
calendar.set(Calendar.HOUR_OF_DAY, hours)
|
58
|
60
|
calendar.set(Calendar.MINUTE, minutes)
|
|
@@ -63,6 +65,22 @@ fun String.hourToCurrentDate(formatType: String = "HH:mm:ss"): Date {
|
63
|
65
|
}
|
64
|
66
|
}
|
65
|
67
|
|
|
68
|
+fun String.hourToCurrentDateLong(formatType: String = "HH:mm:ss"): Long {
|
|
69
|
+ try {
|
|
70
|
+ val simpleDateFormat = SimpleDateFormat(formatType)
|
|
71
|
+ val parse = simpleDateFormat.parse(this)
|
|
72
|
+ val calendar = Calendar.getInstance()
|
|
73
|
+ val year= calendar.get(Calendar.YEAR)
|
|
74
|
+ val day = calendar.get(Calendar.DAY_OF_YEAR)
|
|
75
|
+ calendar.timeInMillis=parse.time
|
|
76
|
+ calendar.set(Calendar.YEAR,year)
|
|
77
|
+ calendar.set(Calendar.DAY_OF_YEAR,day)
|
|
78
|
+ return calendar.time.time
|
|
79
|
+ } catch (e: Exception) {
|
|
80
|
+ return Date().time
|
|
81
|
+ }
|
|
82
|
+}
|
|
83
|
+
|
66
|
84
|
fun Date.getBetweenDay(date: Date): String {
|
67
|
85
|
try {
|
68
|
86
|
var l = (this.time - date.time) / 1000 / 60 / 60 / 24
|
|
@@ -256,19 +274,20 @@ fun Context.getVersionName(): String {
|
256
|
274
|
}
|
257
|
275
|
|
258
|
276
|
//判断是否是链接
|
259
|
|
-fun String.isUrl():Boolean{
|
260
|
|
- var rgex="^http(s)?:\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- .\\/?%&=]*)?".toRegex()
|
261
|
|
- return rgex.containsMatchIn(this)
|
|
277
|
+fun String.isUrl(): Boolean {
|
|
278
|
+ var rgex = "^http(s)?:\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- .\\/?%&=]*)?".toRegex()
|
|
279
|
+ return rgex.containsMatchIn(this)
|
262
|
280
|
}
|
|
281
|
+
|
263
|
282
|
//移除标点
|
264
|
|
-fun String.removePunctuation():String{
|
|
283
|
+fun String.removePunctuation(): String {
|
265
|
284
|
return try {
|
266
|
|
- if (this.isNotBlank()){
|
|
285
|
+ if (this.isNotBlank()) {
|
267
|
286
|
this.replace(Regex("[^\\w\\s]"), "")
|
268
|
|
- }else{
|
|
287
|
+ } else {
|
269
|
288
|
""
|
270
|
289
|
}
|
271
|
|
- }catch (e:java.lang.Exception){
|
|
290
|
+ } catch (e: java.lang.Exception) {
|
272
|
291
|
""
|
273
|
292
|
}
|
274
|
293
|
}
|