时间字符串的处理

mac2022-06-30  26

  

let time = '2019-7-24 12:6:23' //eg:2019年7月24日 12时6分23秒 //方案一:一路replace time = time.replace('-','年').replace('-','月').replace('-','日').replace(':','时').replace(':','分').replace(':','秒') //方案二:获取值的方法,再按需求拼接字符串(基于split()) let ary = time.split(/?:|-|:/g); time = `${ary[0]}年${ary[1]}月${ary[2]}日${ary[3]}时${ary[4]}分${ary[5]}秒`; //不足十位补零,补零函数,按需使用 let addzero = (val)=>val.length<2?'0'+val:val;

 

转载于:https://www.cnblogs.com/angle-xiu/p/11325130.html

最新回复(0)