String str = "123456";
// 可以使用任意字符串分隔,如$1-
String result1 = str.replaceAll("(.{2})(?=.{2})", "$1 ");
String result2 = str.replaceAll("(.{2})(?=.{2})", "$1-");
结果如下
2023-10-31 20:08:22
String str = "123456";
// 可以使用任意字符串分隔,如$1-
String result1 = str.replaceAll("(.{2})(?=.{2})", "$1 ");
String result2 = str.replaceAll("(.{2})(?=.{2})", "$1-");
结果如下