Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 890
germainelol Avatar asked Aug 25 '15 15:08

germainelol


People also ask

How do you convert dates to seconds?

Create a Date object using the Date() constructor. Get a timestamp in milliseconds using the geTime() method. Convert the result to seconds by dividing by 1000 .

How do I convert dates to seconds in bash?

Thanks it's works, i do start=$(date -d"$DateStart" +%s) and end=$(date -d"$DateEnd" +%s) and after time=$(end-start).

How do you find date time and seconds?

Use the total_seconds() method of a timedelta object to get the number of seconds since the epoch. Use the timestamp() method. If your Python version is greater than 3.3 then another way is to use the timestamp() method of a datetime class to convert datetime to seconds.


1 Answers

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 
like image 161
tymeJV Avatar answered Oct 04 '22 12:10

tymeJV