js如何把字符串数字转换成日期类型,如(20140903)转换成日期格式(2014-09-03)
20140903.substring(0, 4)+'-' +20140903.substring(4,2) + '-' + 20140903.substring(6,2)
StringToDate
通过正则表达式将字符串转换成javascript可以识别的格式,参考代码:
var str = '20140903'; var date_str = str.replace(/(\d{4})(\d{2})(\d{2})/g,'$1-$2-$3'); console.log(new Date(date_str));