当前位置:网站首页>Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
2022-07-02 06:22:00 【原小明】
正则匹配
fun valiDateTimeWithLongFormat(timeStr: String): Boolean {
val format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) " + "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
var pattern = Pattern.compile(format)
var matcher = pattern.matcher(timeStr)
if (matcher.matches()) {
pattern = Pattern.compile("(\\d{4})-(\\d+)-(\\d+).*")
matcher = pattern.matcher(timeStr)
if (matcher.matches()) {
val y = Integer.valueOf(matcher.group(1))
val m = Integer.valueOf(matcher.group(2))
val d = Integer.valueOf(matcher.group(3))
if (d > 28) {
val c = Calendar.getInstance()
c.set(y, m - 1, 1)
val lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH)
return lastDay >= d
}
}
return true
}
return false
}
边栏推荐
- 提高用户体验 防御性编程
- The Chinese word segmentation task is realized by using traditional methods (n-gram, HMM, etc.), neural network methods (CNN, LSTM, etc.) and pre training methods (Bert, etc.)
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
- TensorRT的功能
- Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
- Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
- Decryption skills of encrypted compressed files
- 10 erreurs classiques de MySQL
- Cglib代理-代码增强测试
- IDEA公布全新默认UI,太清爽了(内含申请链接)
猜你喜欢
随机推荐
RestTemplate请求时设置请求头,请求参数,请求体。
数据科学【八】:SVD(一)
AWD学习
LeetCode 83. Delete duplicate elements in the sorting linked list
Mech 3002 explanation
Amazon AWS data Lake Work Pit 1
Code skills - Controller Parameter annotation @requestparam
CUDA中内置的Vector类型和变量
New version of dedecms collection and release plug-in tutorial tool
Sentinel 阿里开源流量防护组件
LeetCode 78. subset
深入学习JVM底层(四):类文件结构
Summary of advertisement business bug replay
LeetCode 83. 删除排序链表中的重复元素
10 erreurs classiques de MySQL
Cglib代理-代码增强测试
深入学习JVM底层(二):HotSpot虚拟机对象
LeetCode 39. 组合总和
Don't use the new WP collection. Don't use WordPress collection without update
CUDA中的异步数据拷贝








