当前位置:网站首页>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
}
边栏推荐
- Mech 3002 explanation
- Cglib agent - Code enhancement test
- Find the highest value of the current element Z-index of the page
- 深入学习JVM底层(四):类文件结构
- 阿里云MFA绑定Chrome浏览器
- DeprecationWarning: .ix is deprecated. Please use.loc for label based indexing or.iloc for positi
- Lucene Basics
- WLAN相关知识点总结
- Ruijie ebgp configuration case
- Golang--map扩容机制(含源码)
猜你喜欢
随机推荐
CUDA与Direct3D 一致性
Use of Arduino wire Library
Sudo right raising
日期时间API详解
Introduce two automatic code generators to help improve work efficiency
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
标签属性disabled selected checked等布尔类型赋值不生效?
Code skills - Controller Parameter annotation @requestparam
CUDA中的异步数据拷贝
LeetCode 47. 全排列 II
Idea announced a new default UI, which is too refreshing (including the application link)
LeetCode 83. 删除排序链表中的重复元素
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
底层机制Mvcc
The intern left a big hole when he ran away and made two online problems, which made me miserable
Distributed transactions: the final consistency scheme of reliable messages
Does the assignment of Boolean types such as tag attribute disabled selected checked not take effect?
Pbootcms collection and warehousing tutorial quick collection release
Amazon AWS data Lake Work Pit 1
Name six schemes to realize delayed messages at one go