本文介绍了如何在javascript中将字符串转换为Unix时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串2013-09-05 15:34:00转换为javascript中的Unix时间戳。谁能告诉你怎么做?谢谢。
I want to convert a string "2013-09-05 15:34:00" into a Unix timestamp in javascript. Can any one tell how to do that? thanks.
推荐答案您可以初始化Date对象并调用getTime()以unix形式获取它。它以毫秒为单位,因此您需要除以1000才能在几秒钟内得到它。
You can initialise a Date object and call getTime() to get it in unix form. It comes out in milliseconds so you'll need to divide by 1000 to get it in seconds.
(new Date("2013/09/05 15:34:00").getTime()/1000)它可能有小数位,所以将它包装在Math.round中就可以清除它。
It may have decimal bits so wrapping it in Math.round would clean that.
Math.round(new Date("2013/09/05 15:34:00").getTime()/1000)更多推荐
如何在javascript中将字符串转换为Unix时间戳?
发布评论