From a9f1a8fb1414825c7c33d258c81aa911e90ddaca Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Thu, 25 Mar 2021 00:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/utils/RegexUtil.java | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java index c26dd2f..e1ce160 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java @@ -1,6 +1,5 @@ package com.cm.common.utils; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -47,6 +46,26 @@ public class RegexUtil { * 时间戳格式 */ private static final Pattern PATTERN_DATETIME = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*(\\s+)([0-1][0-9]|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))*$"); + /** + * 时间戳 + */ + private static final Pattern PATTERN_YYYY_MM_DD = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])$"); + /** + * 时间戳 + */ + private static final Pattern PATTERN_YYYY_MM_DD_HH_MM_SS = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])$"); + /** + * 时间戳(毫秒) + */ + private static final Pattern PATTERN_YYYY_MM_DD_HH_MM_SS_ZZZ = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])(\\d{3})$"); + /** + * 时间戳 + */ + private static final Pattern PATTERN_HH_MM_SS = Pattern.compile("^([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])$"); + /** + * 时间戳(毫秒) + */ + private static final Pattern PATTERN_HH_MM_SS_ZZZ = Pattern.compile("^([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])(\\d{3})$"); /** * 身份证 */ @@ -159,6 +178,55 @@ public class RegexUtil { public static boolean isDatetime(String input) { return PATTERN_DATETIME.matcher(input).matches(); } + /** + * 判断时间时间戳 + * + * @param input + * @return + */ + public static boolean isYyyyMmDd(String input) { + return PATTERN_YYYY_MM_DD.matcher(input).matches(); + } + + /** + * 判断时间时间戳 + * + * @param input + * @return + */ + public static boolean isYyyyMmDdHhMmSs(String input) { + return PATTERN_YYYY_MM_DD_HH_MM_SS.matcher(input).matches(); + } + + /** + * 判断时间时间戳 + * + * @param input + * @return + */ + public static boolean isYyyyMmDdHhMmSsZzz(String input) { + return PATTERN_YYYY_MM_DD_HH_MM_SS_ZZZ.matcher(input).matches(); + } + + /** + * 判断时间时间戳 + * + * @param input + * @return + */ + public static boolean isHhMmSs(String input) { + return PATTERN_HH_MM_SS.matcher(input).matches(); + } + + /** + * 判断时间时间戳 + * + * @param input + * @return + */ + public static boolean isHhMmSsZzz(String input) { + return PATTERN_HH_MM_SS_ZZZ.matcher(input).matches(); + } /** * 判断身份证