当前位置:网站首页>Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
2022-07-02 06:35:00 【Xiao Ming Yuan】
Regular matching
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
TensorRT的数据格式定义详解
js中正则表达式的使用
Alibaba cloud MFA binding Chrome browser
FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
介绍两款代码自动生成器,帮助提升工作效率
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
In depth understanding of JUC concurrency (I) what is JUC
【张三学C语言之】—深入理解数据存储
栈(线性结构)
随机推荐
FE - Eggjs 结合 Typeorm 出现连接不了数据库
浅谈三点建议为所有已经毕业和终将毕业的同学
2020-9-23 QT的定时器Qtimer类的使用。
分布式事务 :可靠消息最终一致性方案
Redis - grande question clé
Selenium+msedgedriver+edge browser installation driver pit
MySQL的10大經典錯誤
链表(线性结构)
Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
实现strStr() II
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
AWD学习
Sentinel rules persist to Nacos
Functions of tensorrt
底层机制Mvcc
ShardingSphere-JDBC篇
20201025 Visual Studio2019 QT5.14 信号和槽功能的使用
Vector types and variables built in CUDA
IDEA公布全新默认UI,太清爽了(内含申请链接)
Cglib agent - Code enhancement test