javascript中字符串转时间戳

字符串转日期对象

 

<script>
	function get_unix_time(dateStr)
{
    var newstr = dateStr.replace(/-/g,'/'); 

    var date =  new Date(newstr); 
    var time_str = date.getTime().toString();
    return time_str/1000;
}
console.log("1399479731")
console.log(get_unix_time("2014-12-31"))
console.log(get_unix_time("2015-02-08 00:22:11"))
</script>

 

  

 

  

 

posted @ 2014-12-31 14:02  开水中的糖  阅读(221)  评论(0)    收藏  举报