Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement JavaScript time zone, short date, long date and full date

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the JavaScript time zone, short date, long date and full date how to achieve the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe you read this JavaScript time zone, short date, long date and full date how to achieve the article will have a harvest, let's take a look at it.

Time zone

When setting a date, if you do not specify a time zone, JavaScript uses the browser's time zone.

When the date is obtained, if the time zone is not specified, the result is converted to the browser time zone.

In other words, if the date / time is created in GMT (Greenwich mean time), the date / time will be converted to CST (China Standard time) if the user browses from China.

JavaScript short date

Short dates usually use syntax like "MM/DD/YYYY":

Example

Var d = new Date ("02Accord 19max 2018")

Warning

In some browsers, a month without a leading zero may produce an error:

Var d = new Date ("2018-2-19")

The behavior of 'YYYY / MM / DD' is not defined.

Some browsers try to guess the format. Some return NaN.

Var d = new Date ("2018-02-19")

The behavior of "DD-MM-YYYY" is also undefined.

Some browsers try to guess the format. Some return NaN.

Var d = new Date ("19-02-2018")

JavaScript long date

Long dates are usually written in syntax like "MMM DD YYYY":

Example

Var d = new Date ("Feb 19 2018")

Months and days can appear in any order:

Example

Var d = new Date ("19 Feb 2018")

Also, the month can be written in its full name (January) or abbreviated (Jan):

Example

Var d = new Date ("February 19 2018")

Example

Var d = new Date ("Feb 19 2018")

Commas are ignored and are not case-sensitive:

Example

Var d = new Date ("FEBRUARY, 25, 2015")

JavaScript full date

JavaScript accepts a date string in full JavaScript format:

Example

Var d = new Date ("Mon Feb 19 2018 06:55:23 GMT+0100 (W. Europe Standard Time)")

JavaScript ignores errors in date name and time parentheses:

Example

Var d = new Date ("Fri Mar 26 2018 09:56:24 GMT+0100 (Tokyo Time)")

This is the end of the article on "how to achieve JavaScript time zone, short date, long date and full date". Thank you for reading! I believe you all have a certain understanding of the knowledge of "JavaScript time zone, short date, long date and full date". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report