Friday, April 18, 2008

Java Script Tips 1

Time Date Function In JavaScript

# Create new Date object. This is created thus:

var date_variable = new Date;

# From this object, extract the various elements of Date such as the Year, Month, Time, etc. using the methods defined in the Date class. The syntax for extraction:

var new_variable = date_variable.methodName();

The extracted value is stored in the variable new_variable. The various methods and their function are described below:

Method Name Function

getYear() Returns the year
getMonth() Returns the month(0-12)
getDay() Returns the day(0-7: where 0 refers to Sunday, 1 to Monday and so on)
getDate() Returns the date(0-31)
getHour() Returns the hour(0-24)
getMinutes() Returns the minutes(0-60)
getSeconds() Returns the seconds(0-60)

No comments: