Home  >  Article  >  Web Front-end  >  How to Parse an ISO 8601 Date String in JavaScript?

How to Parse an ISO 8601 Date String in JavaScript?

Susan Sarandon
Susan SarandonOriginal
2024-11-01 10:41:02426browse

How to Parse an ISO 8601 Date String in JavaScript?

Parsing ISO 8601 Date in JavaScript

When working with date and time in JavaScript, it's common to encounter the ISO 8601 standard. This format, expressed as CCYY-MM-DDThh:mm:ssTZD, represents the date and time in a standardized way, making it easy for systems to interpret and exchange.

To convert an ISO 8601 date into JavaScript, the key step is to utilize the built-in Date object. The Date object has a constructor that accepts an ISO 8601 string as its first argument. This constructor will create a Date object representing the specified date and time.

For example, let's say you have the following ISO 8601 date:

2014-04-07T13:58:10.104Z

You can convert this date into JavaScript by creating a new Date object as follows:

var d = new Date("2014-04-07T13:58:10.104Z");

The d variable now contains a Date object that represents the date and time contained in the ISO 8601 string. You can then use the methods and properties of the Date object to manipulate and format the date and time as needed.

The above is the detailed content of How to Parse an ISO 8601 Date String 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