Home > Web Front-end > JS Tutorial > body text

How to Parse ISO 8601 Dates in JavaScript?

Patricia Arquette
Release: 2024-10-26 05:31:31
Original
977 people have browsed it

How to Parse ISO 8601 Dates in JavaScript?

Parsing ISO 8601 Date in JavaScript

ISO 8601 date format is widely used due to its consistency and readability. However, parsing such dates into JavaScript can be challenging. To assist with this task, we can leverage the native Date object's ability to handle 8601 as its primary parameter.

For instance, consider the following ISO 8601 date:

CCYY-MM-DDThh:mm:ssTZD
Copy after login

To parse this date into JavaScript, we can use the following code:

<code class="js">var d = new Date("2014-04-07T13:58:10.104Z");</code>
Copy after login

By passing the ISO 8601 date as an argument to the Date constructor, we create a JavaScript date object that represents the specified date and time. The console.log() method is then used to display the parsed date object as a string, formatted in the browser's default locale.

The above is the detailed content of How to Parse ISO 8601 Dates in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!