
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get a Timestamp in JavaScript
We are required to depict the ways in which we can access the current timestamp in JavaScript in −
---seconds
---milliseconds
JavaScript works with the number of milliseconds since the epoch whereas most other languages work with the seconds.
This will give you a Unix timestamp (in seconds) −
const date = new Date(); const unix = Math.round(+date / 1000); console.log(unix);
This will give you the milliseconds since the epoch (not Unix timestamp) −
const date = new Date(); const milliseconds = date.getTime(); console.log(milliseconds);
Advertisements