Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting YYYY-MM-DD to unix timestamp in Javascript

Tags:

javascript

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?

like image 606
Elitmiar Avatar asked Jun 06 '11 14:06

Elitmiar


People also ask

What is a Unix timestamp JavaScript?

The UNIX timestamp is defined as the number of seconds since January 1, 1970 UTC. In JavaScript, in order to get the current timestamp, you can use Date. now() . It's important to note that Date. now() will return the number of milliseconds since January, 1 1970 UTC.

What is Moment () Unix ()?

The moment(). unix() function is used to get the number of seconds since the Unix Epoch.

Is Unix timestamp in seconds or milliseconds?

Unix is an operating system originally developed in the 1960s. Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.

How do I convert date to epoch time in Excel?

Convert date to timestamp Select a blank cell, suppose Cell C2, and type this formula =(C2-DATE(1970,1,1))*86400 into it and press Enter key, if you need, you can apply a range with this formula by dragging the autofill handle. Now a range of date cells have been converted to Unix timestamps.


1 Answers

You can write new Date("2011-01-02").getTime() / 1000

like image 184
SLaks Avatar answered Sep 30 '22 11:09

SLaks