js将日期格式的时间转成时间戳,方便做时间对比

来源:互联网 发布:淘宝二手手机靠谱么 编辑:程序博客网 时间:2024/06/06 21:10
前端有时候可能要从日期控件中拿到日期,然后参与计算,下边记录一个把日期字符串转换成时间戳的小函数。
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);
}


转载链接:http://blog.sina.com.cn/s/blog_97688f8e0101wmha.html

参考链接:http://tool.chinaz.com/Tools/unixtime.aspx

0 0
原创粉丝点击