Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How can I get seconds since epoch in JavaScript?
To get seconds since epoch, use the below syntax −
var anyVariableName= new Date(); Math.round(yourDateVariableName.getTime() / 1000);
At first, get the current date −
var currentDate= new Date();
Now, get seconds since epoch −
Example
var currentDate= new Date(); var epochSeconds = Math.round(currentDate.getTime() / 1000); console.log(epochSeconds);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo67.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo67.js 1594821507
Advertisements
