- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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);
- Related Articles
- How do you get a timestamp in JavaScript?
- How to get timestamp using MySQL?
- How to get the Unix timestamp in C#
- How to convert a Unix timestamp to time in JavaScript?
- How to get day name from timestamp in MySQL?
- How to get yesterday records from timestamp in Android sqlite?
- How to get current timestamp and relative timestamps in PostgreSQL?
- How to check Leap Year in Java 8 How to get current timestamp in Java 8?
- Get only the date in timestamp in MySQL?
- How to convert from Unix timestamp to MySQL timestamp value?
- Get timestamp date range with MySQL Select?
- Python - Get the weekday from Timestamp object in Pandas
- Get the record of a specific year out of timestamp in MySQL?
- How to get a particular anchor in a document in JavaScript?
- How to get beginning of the first day of this week from timestamp in Android sqlite?

Advertisements