当前位置:网站首页>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
}
边栏推荐
- Find the highest value of the current element Z-index of the page
- LeetCode 47. 全排列 II
- 深入学习JVM底层(二):HotSpot虚拟机对象
- Golang--map扩容机制(含源码)
- LeetCode 283. Move zero
- Redis——缓存击穿、穿透、雪崩
- Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
- CUDA中的动态全局内存分配和操作
- Sentinel规则持久化到Nacos
- 递归(迷宫问题、8皇后问题)
猜你喜欢
WLAN相关知识点总结
Decryption skills of encrypted compressed files
LeetCode 90. 子集 II
Singleton mode compilation
一起学习SQL中各种join以及它们的区别
日期时间API详解
The intern left a big hole when he ran away and made two online problems, which made me miserable
Summary of WLAN related knowledge points
PgSQL学习笔记
Code skills - Controller Parameter annotation @requestparam
随机推荐
Redis - hot key issues
Data science [9]: SVD (2)
LeetCode 83. 删除排序链表中的重复元素
LeetCode 40. Combined sum II
BGP中的状态机
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
LeetCode 39. 组合总和
深入了解JUC并发(二)并发理论
ROS create workspace
Does the assignment of Boolean types such as tag attribute disabled selected checked not take effect?
Web components series (VIII) -- custom component style settings
栈(线性结构)
【程序员的自我修养]—找工作反思篇二
Is there a really free applet?
Log (common log framework)
BGP 路由優選規則和通告原則
LeetCode 77. combination
【每日一题】—华为机试01
LeetCode 283. Move zero
递归(迷宫问题、8皇后问题)