代码改变世界

java 时间正则表达式

2020-03-18 11:29  crazy菜鸟  阅读(3724)  评论(0编辑  收藏  举报
//yyyy-MM-dd  yyyy/MM/dd yyyy.MM.dd yyyyMMdd
String dateReg = "\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2}";

//HH:mm:ss
String timeReg1 = "([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$";

//HH:mm
String timeReg2 = "([0-1]?[0-9]|2[0-3]):([0-5][0-9])$";

//yyyy-MM-dd HH:mm:ss
String dateTimeReg1 ="\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2} ([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$";

//yyyy-MM-dd HH:mm
String dateTimeReg2 ="\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2} ([0-1]?[0-9]|2[0-3]):([0-5][0-9])$";