public static void main(String[] args) {
String name = "2023-02-30 09:30:00 cjj_pdf_13-陈建江 2023-01-30 09:30";
// todo 格式化时间
String regex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(name);
while (matcher.find()) {
String dateStr = matcher.group();
String newDateStr = dateStr.replaceAll("-","")
.replaceAll(" ","")
.replaceAll(":","");
name = name.replaceAll(dateStr, newDateStr);
}
System.out.println(name);
}
JAVA8 时间字符串去空格、冒号和横杠
最新推荐文章于 2024-08-15 14:47:41 发布