JS Get time Zone

Source: Internet
Author: User
Tags local time

JS's time zone function:

Set Datename to create a Date object

====================
Datename.gettimezoneoffset ()
--Get the difference between local time and GMT time (GMT), and the return value is measured in minutes
====================

Example: Get GMT time and time in any time zone based on local time

D=new Date (); Create a Date Object
LocalTime = D.gettime ();
Localoffset=d.gettimezoneoffset () *60000; The number of milliseconds to get local time offset
UTC = LocalTime + localoffset; UTC is GMT time
offset = 10; Take Hawaii time as an example, East 10 district
Hawaii = UTC + (3600000*offset);
nd = new Date (Hawaii);
Document.writeln ("Hawaii time is" + nd.tolocalestring () + <br> ");

============================
DATE.UTC (year, month, day, hours, minutes, seconds, MS)

--Constructs a Date object in GMT time and returns the Date object
==============================

Creating a Date object directly considers the input local time, while creating the object with DATE.UTC is considered to be the GMT time

============================
Datename.toutcstring ()
Datename.togmtstring ()
--Output GMT time
============================

The two functions are the same. The latter is considered obsolete.

The function outputs GMT time relative to the tolocalestring output local time

============================
Other
============================

getUTCDate () function--Returns the day of the month in World Standard Time (UTC) in the Date object (1-31)
GetUTCDay () function--Returns the day of the week in World Standard Time (UTC) in the Date object (0-6)
getUTCFullYear () function--Returns a four-bit year in world standard Time (UTC) in a Date object
getUTCHours () function--Returns the number of hours in world standard Time (UTC) represented in the Date object (0-23)
getUTCMilliseconds () function--Returns the number of milliseconds in world standard Time (UTC) in the Date object (0-999)
getUTCMinutes () function--Returns the number of minutes in world standard Time (UTC) represented in the Date object (0-59)
getUTCMonth () function--Returns the number of months in world standard Time (UTC) in a Date object (0-11)
getUTCSeconds () function--Returns the number of seconds in world standard Time (UTC) in a Date object (0-59)

SetUTCDate () function--sets the day of the month in World Standard Time (UTC) in the Date object, and returns the number of milliseconds (timestamp) between the Date object from midnight January 1, 1970
setUTCFullYear () function--sets the year, month, and day in world Standard Time (UTC) in the Date object, and returns the number of milliseconds (timestamp) between the Date object from midnight January 1, 1970
The setUTCHours () function---Sets the hour, minute, second, and millisecond in world standard Time (UTC) in the Date object, and returns the number of milliseconds between the Date object and Midnight January 1, 1970 (timestamp)
setUTCMilliseconds () function--sets the number of milliseconds in world standard Time (UTC) in the Date object and returns the number of milliseconds between midnight of the Date object from January 1, 1970 (timestamp)
setUTCMinutes () function--sets the minutes, seconds, in world Standard Time (UTC) in the Date object, and returns the number of milliseconds (timestamp) between the Date object and Midnight January 1, 1970
setUTCMonth () function--sets the day of the month in World Standard Time (UTC) in the Date object, and returns the number of milliseconds (timestamp) between the Date object from midnight January 1, 1970
setUTCSeconds () function--sets the number of seconds, milliseconds, in world standard Time (UTC) in the Date object, and returns the milliseconds between the Date object and Midnight January 1, 1970 (timestamp)

JS Get time Zone

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.