请问各位小哥哥怎么分割日期时间

程序媛
  • 22

这个是后台返回的日期时间createTime: "20210915163538"
想要转换成 2009-12-30 13:28:29 这样的格式
image.png

回复
阅读 527
3 个回答

正则替换

"20210915163538".replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,'$1-$2-$3 $4:$5:$6')
'2021-09-15 16:35:38'
  const numbertime = '20210915163538'
  const year = numbertime.slice(0,4)
  const month = numbertime.slice(4,6)
  const day = numbertime.slice(6,8)
  console.log(year,month,day);
你知道吗?

宣传栏