/** * @describe: Date regular expression format such as: yyyy-MM-dd * @author Lvrenshan * @date April 19, 2018 10:36:36 */ public static final String YMD_REXP = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"; public static boolean YMD_REXP(String date){ Pattern p = Pattern.compile(YMD_REXP); Matches startM = p.matches (date); boolean b = startM.matches(); return b; } /** * @describe: Date regular expression format such as: yyyy-MM-dd HH:mm:ss * @author Lvrenshan * @date April 19, 2018 10:36:36 */ public static final String YMDHMS_REXP = "^(((20[0-3][0-9]-(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|(20[0-3][0-9]-(0[2469]|11)-(0[1-9]|[12][0-9]|30))) (20|21|22|23|[0-1][0-9]):[0-5][0-9]:[0-5][0-9])$"; public static boolean YMDHMS_REXP(String date){ return Pattern.compile(YMDHMS_REXP).matcher(date).matches(); }
Date regular, yyyy-MM-dd regular, yyyy-MM-dd HH:mm:ss regular
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325339717&siteId=291194637
Recommended
Ranking