作者:花落酒未醉 | 来源:互联网 | 2023-05-18 21:42
/*
* title: 将字符串转换成日期类型
* description: 字符串,日期值,来源于 SqlServer 数据库。
* parameters: s = date_str , 形如:'2012-05-09 00:00:00.123'
*
* */
function string2date( s ){
var reg = new RegExp("[- :.]","g");
s = s.replace( reg , ",");
s = s.replace( /,0/g , ",");
s = s.replace( /,00/g , ",0");
console.log('2012 0509 0945');
console.log(s);
var a = s.split(',');
var dt = new Date( a[0],a[1],a[2],a[3],a[4],a[5],a[6] );
console.log(dt);
return dt ;
}