当前位置:网站首页>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
}
边栏推荐
- Eggjs -typeorm 之 TreeEntity 实战
- Golang--map扩容机制(含源码)
- 一口气说出 6 种实现延时消息的方案
- 程序员的自我修养—找工作反思篇
- Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
- Data science [9]: SVD (2)
- Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
- Golang -- map capacity expansion mechanism (including source code)
- 2020-9-23 QT的定时器Qtimer类的使用。
- Flask-Migrate 检测不到db.string() 等长度变化
猜你喜欢

链表(线性结构)

一起学习SQL中各种join以及它们的区别

Sentinel 阿里开源流量防护组件

Distributed transactions: the final consistency scheme of reliable messages

CUDA中的Warp Shuffle

ctf三计

Redis - big key problem

apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted

The intern left a big hole when he ran away and made two online problems, which made me miserable

Detailed definition of tensorrt data format
随机推荐
web自动中利用win32上传附件
Error "list" object is not callable in Web automatic switching window
AWD学习
日期时间API详解
Sentinel rules persist to Nacos
(第一百篇BLOG)写于博士二年级结束-20200818
Code skills - Controller Parameter annotation @requestparam
【张三学C语言之】—深入理解数据存储
Shardingsphere JDBC
Eggjs -typeorm 之 TreeEntity 实战
pytest(3)parametrize参数化
In depth understanding of JUC concurrency (II) concurrency theory
TensorRT的数据格式定义详解
Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
Ruijie ebgp configuration case
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
深入学习JVM底层(三):垃圾回收器与内存分配策略
eslint配置代码自动格式化
FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
记录一次RDS故障排除--RDS容量徒增