logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g JavaScript / Java Site

BellaOnline's JavaScript / Java Editor

g

Introduction to UTC Dates

Guest Author - Julie L Baumler

JavaScript has a number of functions that deal with UTC time, but what is UTC time? According to the US Navel Observatory, UTC time is "Coordinated Universal Time," a coordinated civil time scale "kept by time laboratories around the world ... determined using highly precise atomic clocks." This is approximately the same as Greenwich Mean Time (GMT), but is more precise. A number of nations, such as Morocco, Iceland, and Mali; use UTC directly as their civil time. In the winter, UTC is the civil time for the UK. US Civil Time is determined by a set number of hours offset from UTC. For instance, Arizona (which doesn't keep Daylight Savings Time) is always UTC+7. Beijing, China's timezone is UTC-8 (we'll use this in our examples below.)

Most JavaScript Date methods have an equivalent method that deals with UTC time rather than local time. For instance, getHours() returns hour in local time, while getUTCHours() returns the hour in UTC time. You can get a Date object in human readable form relative to local time using toLocaleString() and relative to UTC using toUTCString(). The JavaScript Date object even has a method named UTC. The UTC() method is a static method used to convert a date in a specific format to milliseconds since January 1, 1970 (relative to UTC) . You can then use the Date() constructor to create a Date object with this value.

For example, China has announced that the opening ceremonies of the 2008 Olympics will be on August 8, 2008 at 8:08pm. We can use JavaScript's UTC() method to find out when this is in local time.

var offset=-8; //offset from UTC
var luckyday=new Date(Date.UTC(2008,7,8,(20 + offset ),8);
document.write(" The 2008 Olympics starts at " + luckyday.toUTCString());
document.write(" In local time this is " + luckyday.toLocaleString())

Note: In the example above, I converted from Beijing time to UTC by adding the offset from UTC ("-8") to the Beijing time - this is why argument 4 of Date.UTC reads "(20 + offset)" above.

If you have JavaScript available in your browser, you can see a live example of this code here.


REFERENCE

Date.UTC( year, month[, day, [hour, [minutes, [seconds, [milliseconds]]]]])

converts the given date into milliseconds since January 1, 1970.

Note: all arguments are digits. As always in JavaScript, a month of 0 is January. If any argument other than year is a larger or smaller number than than possible for the value it represents, it is used to affect the next larger argument for instance, a month of 13 is interpreted as February of the next year and a month of -2 is interpreted as November of the previous year.

SOURCE

U.S. Naval Observatory. "What is Universal Time?." 30 October 2003. U.S. Naval Observatory, Astronomical Applications Department. 6 July 2007. <http://aa.usno.navy.mil/faq/docs/UT.html>
This site needs an editor - click to learn more!

Add Introduction+to+UTC+Dates to Twitter Add Introduction+to+UTC+Dates to Facebook Add Introduction+to+UTC+Dates to MySpace Add Introduction+to+UTC+Dates to Del.icio.us Digg Introduction+to+UTC+Dates Add Introduction+to+UTC+Dates to Yahoo My Web Add Introduction+to+UTC+Dates to Google Bookmarks Add Introduction+to+UTC+Dates to Stumbleupon Add Introduction+to+UTC+Dates to Reddit




Introduction To The JavaScript Date Object
Getting Dates and Parts of Dates in JavaScript
JavaScript/Java Site and Newsletter
RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map


For FREE email updates, subscribe to the JavaScript / Java Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Hearing Dog Tool - Adding Randomness

Hearing Dog Training Tool setTimeout()

GCJ - an Independant Java Implementation

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor