How to use Date object with toISOString() Method In Javascript
The date object comes with a method known as toISOString() which simply returns the date in the date time string format, a format which is based on ISO 8601.
Example: The below code uses the Date object with toISOString() method to log the current date in JavaScript.
Javascript
console.log( new Date().toISOString().split( "T" )[0]); |
Output
2024-01-23
How to Log the Current Date in JavaScript ?
The Date object is an inbuilt object constructor of JavaScript language. It is used to work with dates and times. The Date object is created by using the new keyword, i.e. new Date(). The current date can be logged on the console in JavaScript using the below-discussed methods.
Table of Content
- Using JavaScript Date object
- Using JavaScript Date object with toString() Method
- Using JavaScript Date object with toDateString() Method
- Using JavaScript Date object with toLocaleDateString() Method
- Using JavaScript Date object with toISOString() Method
Contact Us