spacer
Yehuda Shiran October 21, 1999
What Day were you Born on?
Tips: October 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The Date object is one of the more powerful objects in JavaScript. It supports several methods to set and get different portions of the date description. Let's take an example that computes the day of the week of your birthday:

var ar = new Array();
ar[0] = "Sunday";
ar[1] = "Monday";
ar[2] = "Tuesday";
ar[3] = "Wednesday";
ar[4] = "Thursday";
ar[5] = "Friday";
ar[6] = "Saturday";
var birthDay = new Date("January 3, 1978");
var day = birthDay.getDay();
alert("You were born on " + ar[day]);

Notice that Sunday is the first day of the week and its index is 0. Similarly, the first month of the year is January and its numeric value is 0 as well. The following script sets the year, month, and date of the month:

var ar = new Array();
ar[0] = "Sunday";
ar[1] = "Monday";
ar[2] = "Tuesday";
ar[3] = "Wednesday";
ar[4] = "Thursday";
ar[5] = "Friday";
ar[6] = "Saturday";
var birthDay = new Date();
birthDay.setYear(1978);
birthDay.setMonth(0);
birthDay.setDate(3);
var day = birthDay.getDay();
alert("You were born on " + ar[day]);


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint