js怎么把字符串'yyyymmddhhmmss' 转成'yyyy-mm-dd hh:mm:ss'

'yyyymmddhhmmss' 转成'yyyy-mm-dd hh:mm:ss'

阅读 3k
1 个回答

这是正则的方法

var dateStr = '20180418230102';
var reg = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
dateStr = dateStr.replace(reg, '$1-$2-$3 $4:$5:$6');
"2018-04-18 23:01:02"
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题