码迷,mamicode.com
首页 > 编程语言 > 详细

javascript中的小技巧

时间:2014-12-31 14:26:25      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

字符串转日期对象

 

<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>

 

  

 

  

 

javascript中的小技巧

标签:

原文地址:http://www.cnblogs.com/mmdrs/p/4195618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!