Home  >  Article  >  Web Front-end  >  How to Parse ISO 8601 Dates in JavaScript?

How to Parse ISO 8601 Dates in JavaScript?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-26 05:31:31979browse

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

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>

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!

Statement:
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