Introduction to the date and time and presentation standards in JavaScript _ basics

Source: Internet
Author: User
Tags deprecated time zones local time
Preface

The introduction of this article covers the following sections:

1. What does the time standard mean? What are the concepts, associations, and differences between UCT and GMT?

2. What are the criteria for time presentation?

3. JS time in the processing


Date Time Standard

The standard of the date is not much to say--A.D.

is to commemorate the birth of the Jew Jesus (Christ). He was born in the year of 1, before the birth of the year called "BC N Years"

In short, the standard of time is when to start the time with a starting point. For years, for example, if you do not use the year calendar method, it is estimated that the world communication is difficult (new China 54, it is estimated that a lot of foreigners halo)

The time standard is actually quite many.

Atom Time · Coordinated Universal Time (UTC) · Greenwich Peacetime (GMT) · Earth Time (TT) · Mechanical Time (DT)

UTC and GMT are more common in program development and even in daily life.

UTC is the coordinated World time (Universal Time coordinated) English abbreviation, which is defined and recommended by the International Radio Advisory Board and is maintained by the International Time Bureau (BIH) in seconds based timescale. UTC, which corresponds to the average sun on the meridian (i.e. longitude 0 degrees), was previously represented by Greenwich Mean Time (GMT). Beijing time is 8 hours earlier than UTC, with January 1, 1999 0000UTC as an example, UTC time is 0, Beijing time is January 1, 1999 8 o'clock in the morning whole.

GMT (Greenwich Mean time) is Greenwich peacetime:
Since the Earth's orbit is not circular, its operating speed changes with the distance between the Earth and the sun, so it lacks uniformity to see the sun. The length of the sun day is also affected by the tilt of the Earth's rotation axis relative to the orbital plane. To correct the above heterogeneity, astronomers calculate the effect of the Earth's non-circular trajectory and polar axis tilting to the sun. When the sun is flat, it refers to the revised view of the sun. The flat sun on the Greenwich meridian is called the World Time (UT0), also known as Greenwich (GMT).

In order to ensure that the world is coordinated with the world Time (UT1) will not exceed 0.9 seconds, when necessary, in the coordinated world time plus positive or negative leap second. As a result, there are several integer seconds differences between the coordinated world and the International Atomic Time (TAI). The International Earth Rotation NCBs (IERS) in Paris is responsible for deciding when to add leap seconds.

The relationship between the two:

UTC = GMT/+-0.9 s
Therefore, a "leap second" is required between UTC to control the difference.

All the above can not read, in a word, UTC and GMT is the world standard Time, the gap between the two is very small.

Date Time Presentation criteria

The date and time calculation criteria are available. But the expression can also thousand difference.

2013/08/16

08/16/2013

13/08/16

.。。。。。

As a result, ISO has come out and developed a 8601-series "Data storage and Exchange form • Information Exchange, date and time representation".

The third edition is currently iso8601:2004 to replace the first edition iso8601:1988 with the second edition iso8601:2000.

The main sections are listed:

1. The date notation

The year is 4 digits, the month is 2 digits, and the day of the months is 2 digits, for example, the date (August 16, 2013) can be expressed as 2013-08-16, or 20130816.

2. Calendar week and day notation

The number of calendar weeks of the year can be expressed in 2 digits;

Each calendar week starts from Monday, Sunday is the 7th day

3. Time Representation method

The hours, minutes, and seconds are represented by 2 digits, the last of which is a capital letter Z for the UTC time, and the other time zones are represented by the actual time difference. such as UTC time 2:30 P.M. 5 seconds for 14:30:05z or 143005Z, the time of the 22:30:05+08:00 or 223005+0800, can also be reduced to 223005+08.

4. Date and time combination notation

When merging representations, precede the time with a capital letter T, which can be written as 2004-05-03t17:30:08+08:00 or 20040503t173008+08 if you want to indicate the Beijing time May 3, 2004 5:30 P.M. 8 seconds.

What needs to be specifically raised is:

Sunday in the West is as the first day of one weeks

It's the last day in China.

The ISO standard is consistent with China's habits. But at present many software, language and so on are developed abroad, time or the continuation of their own habits.

date and time in Javascript
Method Description FF IE
Date () Returns the date and time of the day. 1 3
GetDate () Returns one day of one months from the Date object (1 ~ 31). 1 3
Getday () Returns one day of the week from the Date object (0 ~ 6). 1 3
GetMonth () Returns the month from the date object (0 ~ 11). 1 3
getFullYear () Returns the year with a four-digit number from the Date object. 1 4
GetYear () Please use the getFullYear () method instead. 1 3
GetHours () Returns the hour of the date object (0 ~ 23). 1 3
Getminutes () Returns the Minutes (0 ~ 59) of the Date object. 1 3
Getseconds () Returns the number of seconds (0 ~ 59) of the Date object. 1 3
Getmilliseconds () Returns the millisecond (0 ~ 999) of the Date object. 1 4
GetTime () Returns the number of milliseconds since January 1, 1970. 1 3
getTimezoneOffset () Returns the minute difference between local time and Greenwich Mean Time (GMT). 1 3
getUTCDate () Returns the day of the month from the date object according to the world (1 ~ 31). 1 4
getUTCDay () Returns the day of the week from the Date object based on the world (0 ~ 6). 1 4
getUTCMonth () Returns the month (0 ~ 11) from the Date object according to the world. 1 4
getUTCFullYear () Returns a four-digit year from the Date object, based on the world. 1 4
getUTCHours () The hour (0 ~ 23) that returns the Date object according to the universal. 1 4
getUTCMinutes () Returns the minute (0 ~ 59) of the date object according to the universal. 1 4
getUTCSeconds () Returns the second (0 ~ 59) of the date object according to the universal. 1 4
getUTCMilliseconds () Returns the millisecond (0 ~ 999) of the date object according to the universal. 1 4
Parse () Returns the number of milliseconds from midnight January 1, 1970 to the specified date (string). 1 3
Setdate () Sets the day of the month in the Date object (1 ~ 31). 1 3
Setmonth () Sets the month in the Date object (0 ~ 11). 1 3
setFullYear () Sets the year (four digits) in the Date object. 1 4
Setyear () Please use the setFullYear () method instead. 1 3
Sethours () Sets the hour in the Date object (0 ~ 23). 1 3
Setminutes () Sets the minutes in the Date object (0 ~ 59). 1 3
Setseconds () Sets the seconds in the Date object (0 ~ 59). 1 3
Setmilliseconds () Sets the milliseconds in the Date object (0 ~ 999). 1 4
SetTime () Sets the Date object in milliseconds. 1 3
setUTCDate () Sets the day of the month in the Date object according to the world (1 ~ 31). 1 4
setUTCMonth () Sets the month in the Date object according to the world (0 ~ 11). 1 4
setUTCFullYear () Sets the year (four digits) in the Date object based on the world. 1 4
setUTCHours () Sets the hour in the Date object according to the world (0 ~ 23). 1 4
setUTCMinutes () Sets the minutes in the date object according to the world (0 ~ 59). 1 4
setUTCSeconds () Sets the second (0 ~ 59) in the Date object according to the world. 1 4
setUTCMilliseconds () Sets the milliseconds in the Date object according to the world (0 ~ 999). 1 4
Tosource () Returns the source code for this object. 1 -
ToString () Converts the Date object to a string. 1 4
toTimeString () Converts the time portion of a Date object to a string. 1 4
toDateString () Converts the date part of a Date object to a string. 1 4
toGMTString () Please use the toutcstring () method instead. 1 3
toUTCString () Converts a Date object to a string according to the universal. 1 4
toLocaleString () Converts the Date object to a string, based on the local time format. 1 3
toLocaleTimeString () Converts the time portion of a Date object to a string, based on the local time format. 1 3
toLocaleDateString () Converts the date part of a Date object to a string, based on the local time format. 1 3
UTC () Returns the number of milliseconds from January 1, 1997 to a specified date according to the Universal. 1 3
ValueOf () Returns the original value of the Date object.

The above also can all do not look, need to specifically say is:

Javascript takes Sunday as the beginning of a week. You have to be careful when using the Getday () method.

Getday () returns the number between 0-6, 2013/08/18 is Sunday, the return value is 0
Copy Code code as follows:

<!--Add by oscar999-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta name= "Author" content= "oscar999" >
<script>
var date = new Date ("2013/08/18");
Alert (Date.getday ());
</script>
</HEAD>

<BODY>

</BODY>
</HTML>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.