 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How to 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
 