- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
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 −
Here, my file name is demo67.js.
This will produce the following output −
- Java Program to get the seconds since the beginning of the Java epoch
- Display seconds since the epoch with Java Date and Time Conversion Character
- Java Program to get Epoch seconds from Instant
- Displaymilliseconds since the epoch with Java Date and Time Conversion Character
- How can I convert 1st January of the current year into epoch?
- How can I convert the epoch stored in MySQL table into readable dates?
- In MySQL, how can I convert a number of seconds into TIMESTAMP?