当前位置:网站首页>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
}
边栏推荐
- Redis - big key problem
- 链表(线性结构)
- Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
- When requesting resttemplate, set the request header, request parameters, and request body.
- Redis——缓存击穿、穿透、雪崩
- It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
- 加密压缩文件解密技巧
- 注解和反射详解以及运用
- 实现strStr() II
- Data science [9]: SVD (2)
猜你喜欢
In depth understanding of JUC concurrency (I) what is JUC
Data science [viii]: SVD (I)
Idea announced a new default UI, which is too refreshing (including the application link)
Pbootcms collection and warehousing tutorial quick collection release
阿里云MFA绑定Chrome浏览器
【张三学C语言之】—深入理解数据存储
LeetCode 90. Subset II
Redis——缓存击穿、穿透、雪崩
Amazon AWS data Lake Work Pit 1
BGP中的状态机
随机推荐
CUDA中的线程层次
IDEA公布全新默认UI,太清爽了(内含申请链接)
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
TensorRT中的循环
【每日一题】—华为机试01
Learn about various joins in SQL and their differences
LeetCode 283. 移动零
Bgp Routing preference Rules and notice Principles
MySql索引
CUDA中的存储空间修饰符
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.)
计算属性普通函数写法 和 set get 写法
一口气说出 6 种实现延时消息的方案
PgSQL学习笔记
Idea announced a new default UI, which is too refreshing (including the application link)
LeetCode 78. 子集
CUDA中内置的Vector类型和变量
ShardingSphere-JDBC篇
Sentinel rules persist to Nacos
实习生跑路留了一个大坑,搞出2个线上问题,我被坑惨了