当前位置:网站首页>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
}
边栏推荐
- Tensorrt command line program
- 广告业务Bug复盘总结
- 底层机制Mvcc
- ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
- Uploading attachments using Win32 in Web Automation
- Win电脑截图黑屏解决办法
- 介绍两款代码自动生成器,帮助提升工作效率
- When requesting resttemplate, set the request header, request parameters, and request body.
- Redis---1.数据结构特点与操作
- eslint配置代码自动格式化
猜你喜欢
广告业务Bug复盘总结
Redis - cluster data distribution algorithm & hash slot
Learn about various joins in SQL and their differences
Redis——Cluster数据分布算法&哈希槽
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
分布式事务 :可靠消息最终一致性方案
Introduce two automatic code generators to help improve work efficiency
In depth understanding of JUC concurrency (II) concurrency theory
Sentinel rules persist to Nacos
Summary of WLAN related knowledge points
随机推荐
pytest(3)parametrize参数化
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
数据科学【八】:SVD(一)
队列(线性结构)
Thread hierarchy in CUDA
奇葩pip install
CUDA用户对象
The intern left a big hole when he ran away and made two online problems, which made me miserable
IDEA公布全新默认UI,太清爽了(内含申请链接)
CUDA中的Warp matrix functions
Decryption skills of encrypted compressed files
RestTemplate请求时设置请求头,请求参数,请求体。
CUDA and Direct3D consistency
Detailed definition of tensorrt data format
Sudo right raising
Three suggestions for all students who have graduated and will graduate
Selenium+msedgedriver+edge browser installation driver pit
CUDA中的函数执行空间说明符
CUDA与Direct3D 一致性
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误