在Javascript中将YYYY-MM-DD转换为Unix时间戳 [英] Converting YYYY-MM-DD to unix timestamp in Javascript
本文介绍了在Javascript中将YYYY-MM-DD转换为Unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将日期转换为格式,例如2011年1月2日到JavaScript中的Unix时间戳,但并不完全知道如何完成.我可以使用以下函数 Math.round((new Date()).getTime()/1000);
来获取当前时间戳,但是不知道如何将给定日期转换为unix时间戳?
I need to convert a date in format eg. 2011-01-02 to a unix timestamp in JavaScript but do not exactly know how to accomplish it. I can get the current timestamp using the following functions Math.round((new Date()).getTime() / 1000);
but do not know how to convert the given date to a unix timestamp?
推荐答案
您可以编写 new Date("2011-01-02").getTime()/1000
这篇关于在Javascript中将YYYY-MM-DD转换为Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文