How to use the toISOString() method In Javascript
The toISOString() method will format the data into the International Standards following the ISO 8601 format.
Syntax:
dateObj.toISOString();
Example: The below code example implements the toISOString() method to format the date object.
const currentDate = new Date();
const formattedDate = currentDate.toISOString();
console.log(formattedDate);
Output
2023-12-29T09:39:27.634Z
How to Format a Date in JavaScript ?
In this article, we will learn about the different ways of formatting a Date object into different date strings of different formats using JavaScript.
We will see the methods of formatting Date objects into various date strings with different formats using JavaScript. Whether you’re building a web application, manipulating data, or simply displaying dates, mastering these techniques will empower you to present dates in the format that best suits your needs. Let’s explore the versatility of date formatting in JavaScript.
The below list contains the different ways of formatting Date in JavaScript:
Table of Content
- Method 1: Using the toDateString() method
- Method 2: Using the toISOString() method
- Method 3: Using the toLocaleDateString() method
- Method 4: Using the toLocaleString() method
- Method 5: Using the Intl.DateTimeFormat() object method
- Method 6: Manually format date using Date methods
Contact Us