如何用正则表达式更改时间格式
目前返回的时间是20180823103000-20180823113000现在希望替换成:2018-08-2310:30:00...
目前返回的时间是20180823103000 - 20180823113000
现在希望替换成:2018-08-23 10:30:00 展开
现在希望替换成:2018-08-23 10:30:00 展开
1个回答
展开全部
匹配正则:(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})
替换语句:$1-$2-$3 $4:$5:$6
java测试代码示例:
public class Demo {
public static void main(String[] args) {
String time = "20180823103000";
String newTime = time.replaceAll("(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})", "$1-$2-$3 $4:$5:$6");
System.out.println(newTime);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询