JavaScript - Converting a Date() into seconds [duplicate]

别来无恙 提交于 2020-01-03 07:37:31

问题


I'm using the Hacker News API made at Algolia here:

https://hn.algolia.com/api

I'm a bit confused as it says to search for posts since a certain time it says to run the following query:

Comments since timestamp X (in second) http://hn.algolia.com/api/v1/search_by_date?tags=comment&numericFilters=created_at_i>X

It says to replace X with a timestamp in seconds, but how exactly would you do this? Let's say the last post I have is at 2015-08-25T15:35:58.000Z. How exactly would I run this query to search for posts since that date? I don't know how to convert this date to seconds...

Thanks in advance!


回答1:


getTime() will get the date in milliseconds, so divide by 1000:

var date = new Date("2015-08-25T15:35:58.000Z");
var seconds = date.getTime() / 1000; //1440516958


来源:https://stackoverflow.com/questions/32208476/javascript-converting-a-date-into-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!