当前位置:网站首页>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
}
边栏推荐
猜你喜欢

Web components series (VIII) -- custom component style settings

Ruijie ebgp configuration case

Sudo right raising

数据科学【八】:SVD(一)

Support new and old imperial CMS collection and warehousing tutorials

栈(线性结构)

Singleton mode compilation

Sublime Text 配置php编译环境

实现strStr() II

Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
随机推荐
Arduino Wire 库使用
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
深入学习JVM底层(四):类文件结构
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
Sublime Text 配置php编译环境
Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
Data science [viii]: SVD (I)
AWD学习
VLAN experiment of switching technology
亚马逊aws数据湖工作之坑1
CUDA用户对象
Monitoring uplink of VRRP
PgSQL学习笔记
CUDA中的Warp matrix functions
LeetCode 27. Removing Elements
Three suggestions for all students who have graduated and will graduate
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
WLAN相关知识点总结
Lucene Basics