Getting UTC Dates in JavaScript

Getting UTC Dates in JavaScript
In a recent article we looked all the methods for getting different parts of a date and time according to the local time. Local time is whatever time and timezone the computer the user is using is set to. Here we look at the methods for getting different parts of a date and time according to UTC time. More information about UTC time is available here

For these examples, date is set to Sat, 07 Jul 2007 14:07:07 GMT using var luckyday=new Date(2007,06,07,07,07,07,07);. If you have JavaScript available in your browser, you can see a live example here.

getUTCMonth()
a number representing the month according to UTC time, 0 for January, 1 for February, ... You can use this as a key to an array of month names or add one to the number to get a human readable month
EXAMPLE: luckyday.getUTCMonth() RESULT: 6


getUTCDate()
the day of the month according to UTC time as a number from 1 to 31 according to UTC time
EXAMPLE: luckyday.getUTCDate() RESULT: 7


getUTCDay()
the day of the week according to UTC time as a number from 0 to 6 where 0 represents Sunday and 6 represents Saturday
EXAMPLE: luckyday.getUTCDay() RESULT: 6


getUTCFullYear()
returns the four digit year according to UTC time
EXAMPLE: luckyday.getUTCFullYear() RESULT: 2007


getUTCHours()
hour of the day on a 24 hour clock according to UTC time(0 to 23)
EXAMPLE: luckyday.getUTCHours() RESULT: 14


getUTCMinutes()
minutes after the hour according to UTC time(0 to 59)
EXAMPLE: luckyday.getUTCMinutes() RESULT: 7


getUTCSeconds()
seconds of the minute according to UTC time(0 to 59)
EXAMPLE: luckyday.getUTCSeconds() RESULT: 7


getUTCMilliseconds()
millionths of a second according to UTC time(0 to 999)
EXAMPLE: luckyday.getUTCMilliseconds() RESULT: 7


This site needs an editor - click to learn more!


You Should Also Read:
Introduction To The JavaScript Date Object
Introduction To UTC Dates
Getting Dates In Local Time

RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map





Content copyright © 2023 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.