js把日期字符串转换成时间戳

来源:互联网 发布:mac iphoto 无法更新 编辑:程序博客网 时间:2024/05/20 06:07
前端有时候可能要从日期控件中拿到日期,然后参与计算,下边记录一个把日期字符串转换成时间戳的小函数。
dateStr格式为“2014-05-08 00:22:11 
function get_unix_time(dateStr)
{
    var newstr = dateStr.replace(/-/g,'/'); 
    var date =  new Date(newstr); 
    var time_str = date.getTime().toString();
    return time_str.substr(0, 10);
}
0 0
原创粉丝点击