How to use Date object with toDateString() Method In Javascript
The date object comes with a method known as toDateString() which simply returns the date portion of this date interpreted in the local timezone.
Example: The below code uses the Date object with toDateString() method to log the current date in JavaScript.
Javascript
// Create a new Date object const currentDate = new Date(); console.log(currentDate.toDateString()); |
Tue Jan 23 2024
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