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

Getting Dates and Parts of Dates in JavaScript

Guest Author - Julie L Baumler

In a recent article we looked at the the JavaScript date object, in general. Here we look at 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.

For these examples, date is set using var now=new Date() when local time was Friday, July 06, 2007 5:54:14 PM on a computer set to (US) Mountain Standard Time. If you have JavaScript available in your browser, you can see a live example here.
getMonth()
a number representing the month, 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: now.getMonth() RESULT: 6
getDate()
the day of the month as a number from 1 to 31
EXAMPLE: now.getDate() RESULT: 6
getDay()
the day of the week as a number from 0 to 6 where 0 represents Sunday and 6 represents Saturday
EXAMPLE: now.getDay() RESULT: 5
getFullYear()
returns the four digit year
EXAMPLE: now.getFullYear() RESULT: 2007
getYear()
returns the two digit year OR the four digit year minus 1900, you should probably avoid using this in favor of getFullYear()
EXAMPLE: now.getYear() RESULT: 07 OR 107 OR even 7
getHours()
hour of the day on a 24 hour clock (0 to 23)
EXAMPLE: now.getHours() RESULT: 17
getMinutes()
minutes after the hour (0 to 59)
EXAMPLE: now.getMinutes() RESULT: 54
getSeconds()
seconds of the minute (0 to 59)
EXAMPLE: now.getSeconds() RESULT: 14
getMilliseconds()
millionths of a second (0 to 999)
EXAMPLE: now.getMilliseconds() RESULT: 937
getTimezoneOffset()
Offset from UTC time in minutes
EXAMPLE: now.getTimezoneOffset() RESULT: 420
getTime()
current time in native JavaScript format, Milliseconds since January 1st, 1970. This is often called UNIX time, since the UNIX operating system popularized this time format.
EXAMPLE: now.getTime() RESULT: 1183769654937
This site needs an editor - click to learn more!

Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Twitter Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Facebook Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to MySpace Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Del.icio.us Digg Getting+Dates+and+Parts+of+Dates+in+JavaScript Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Yahoo My Web Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Google Bookmarks Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Stumbleupon Add Getting+Dates+and+Parts+of+Dates+in+JavaScript to Reddit




Introduction To The JavaScript Date Object
Javascript Resources
JavaScript/Java 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