I. Introduction

1. utc:universal time coordinated.

2. Greenwich Mean Time (gmt)

Greenwich mean time (gmt) is the standard time at the Royal Greenwich Observatory in the suburbs of London,Because the prime meridian is defined by the meridian passing there. In theory,Greenwich Mean Time is the time when the sun crosses the Greenwich Meridian.Due to the uneven speed of the earth's movement in its elliptical orbit,This time may differ from the actual solar time by 16 minutes. The Earth ’s daily rotation is somewhat irregular,And it is slowly slowing down.Therefore, GMT is no longer used as standard time.The current standard time-Coordinated Universal Time (UTC)-is provided by the atomic clock. Beginning February 5, 1924, the Greenwich Observatory will send timing information to the world every hour.UTC is based on the accurate time provided by the standard GMT.

gmt (greenwich mean time)-Greenwich Mean Time,Greenwich Mean Time is the base time for the British Empire in the mid-19th century.It is also the de facto world benchmark time.At that time, it was mainly for the railway system after 1840.It uses the longitude of the Greenwich Observatory as a 0 degree meridian and divides the world into 24 time zones. In addition to being affected by xenophobia, nationalism, and some anti-British sentiments during certain periods,Its status has never wavered.

The difference between gmt and utc

A gmt watch is a watch that displays time in two or more time zones.No matter what wayThe most direct way to display multiple time zones is to install multiple movements in one case.But the most economical and common method is to attach a rotating bezel with a 12-hour or 24-hour time scale.The use of the rotating bezel is very simple,Just align the number on the bezel corresponding to the time in the second time zone with the hour hand on the dial.If the dial time is London time,Then turn the bezel clockwise for an hour,Indicating Continental European Time,Turn it counterclockwise for eight hours,It is the West Coast time.

Setting the dial time to home or destination time depends on the user's preferences.But because the 12-hour watch ca n’t distinguish day and night,It is usually reasonable to set the local time.One event complicated the definition of gmt:on January 1, 1972, UTC (Coordinated Universal Time) became the new world standard time.

For convenience, Usually recorded as universal time coordinated. Also for convenience,Without needing to be accurate to the second,Gmt and utc are also generally considered equivalent.Although UTC is more scientific and precise,But for watchers and collectors,gmt is still more popular.Many people think thatUTC is a means by which Paris attempts to position itself as a world timing center.In fact, it's based on atomic hours,A time measurement system that is as close as possible to Universal Time in time.Its emergence is the need for precise timing in modern society.

Atomic time is different from previous timing systems.It is very accurate and not based on the average solar time in a place,But in the case of uneven rotation speed of the earth,The time difference between the atomic time and the world time accumulates over time,Therefore, UTC will add a positive or negative leap second to compensate after a period of time.As a result, there are several whole-second differences between Coordinated Universal Time and International Atomic Time (tai).The International Bureau of Earth Rotation Affairs (iers) in Paris decides when to join leap seconds.

Beijing time differs from Greenwich Mean Time or UTC time by 8 time zones. Beijing, Shanghai, and Chongqing are located in East 8th District, so Beijing time 2013-1-1 0:00:00, converted to UTC time is:tue jan 1 00:00:00 utc+ 0800 2013, 8 hours passed.

Conversion from local time to UTC timeThe conversion from local time to UTC time,Proceed as follows:

1.Convert string date to date data typeIf it is already a date type,This step can be omitted.

You can use the function in the following example to do the conversion.

2.Get UTC date dataIncluding the date,Hours, minutes, and seconds are obtained using the getutc *** () method.

Get year:var y=date.getutcfullyear ();

Get month:var m=date.getutcmonth ();

Get Date:var d=date.getutcdate ();

Get hours:var h=date.getutchours ();

Get minutes:var m=date.getutcminutes ();

Get seconds:var s=date.getutcseconds ();

Here date is date type data.

Note:It is problematic to use the method without utc (for example:date.getfullyear, date.getmonth). When the next conversion is performed,The result will be wrong.

3.Conversion using date.utc () functionConvert the date data obtained in step 2 to UTC time (actually the number of milliseconds since 1700)

var utc=date.utc (y, m, d, h, m, s);

Here, y, m, d, h, m, and s respectively represent the year, month, day, hour, minute, and second values ​​obtained in step 2.

Conversion of UTC Date to Local Dateutc date to local date conversion is much simpler,First convert UTC time to date format,And then converted to the local date format,E.g:

var date2=new date (utc);
var localestring=date2.tolocalestring ();

Or as long as the date

var localedatestring=date2.tolocaledatestring ();

Or as long as

var localetimestring=date2.tolocaletimestring ();


//Date addition and subtraction calculation
function dateadd (sdate, delta, ymdh) {
 if (! sdate) return;
 if (typeof sdate == "object") sdate=sdate.tolocalestring ();
 /(\ d {4}) [\ d] (\ d {1,2}) [\ d] (\ d {1,2}) [\ d]?\ s (\ d {1, 2}):(\ d {1,2}):(\ d {1,2}) /. Exec (sdate);
 var a=[0,0,0,0];
 switch (ymdh) {
  case "y":
   a=[delta, -1, 0, 0];
  case "m":
   a=[0, delta-1, 0, 0];
  case "h":
   a=[0, -1, 0, delta];
   a=[0, -1, delta, 0];
 println ("date:" + (parseint (regexp. $1) + a [0]) + "-" + (parseint (regexp. $2) + a [1]) + "-" + (parseint (regexp. $3) + a [2])
  + "" + (parseint (regexp. $4) + a [3]) + ":" + regexp. $5 + ":" + regexp. $6);
 return new date (parseint (regexp. $1) + a [0], parseint (regexp. $2) + a [1], parseint (regexp. $3) + a [2], parseint (regexp. $4) + a [3 ], regexp. $5, regexp. $6);
 //utc conversion
 println ("---------------------------------------------") ;
 var sdate="2013-01-01 00:00:00.0";
 var d=dateadd (sdate, 0);
 var d2=date.utc (d.getutcfullyear (), d.getutcmonth (), d.getutcdate (), d.getutchours (), d.getutcminutes (), d.getutcseconds ());
 println ("Original Date:" + sdate);
 println ("d2:" + d2);
 println ("d3:" + new date (d2));
 println ("d4:" + new date (d2) .tolocalestring ());
 println ("d5:" + d2.tolocalestring ());

Test Results:

date:2013-0-1 0:00:00
Original date:2013-01-01 00:00:00.0
d3:tue jan 1 00:00:00 utc+ 0800 2013
d4:January 1, 2013 0:00:00

You can see that the UTC time is actually a long series of milliseconds since 1970.

  • Previous Set as homepage and add favorites to each browser based on JavaScript code
  • Next Strcmp () and strcasecmp () function string comparison usage analysis in PHP