Thursday, April 4, 2013

javascript Functions on the Date Object


The Date object is used to work with dates and times.

Syntax for creating a Date object: 
var myDate=new Date()

Date Object Properties

Constructor Returns a reference to the Date function that created the object
Prototype Allows you to add properties and methods to the object

Date Object Methods
Date() Returns today's date and time
getDate() Returns the day of the month from a Date object (from 1-31)
getDay() Returns the day of the week from a Date object (from 0-6)
getFullYear() Returns the year, as a four-digit number, from a Date object
getHours() Returns the hour of a Date object (from 0-23)
getMilliseconds() Returns the milliseconds of a Date object (from 0-999)
getMinutes() Returns the minutes of a Date object (from 0-59)
getMonth() Returns the month from a Date object (from 0-11)
getSeconds() Returns the seconds of a Date object (from 0-59)
getTime() Returns the number of milliseconds since midnight Jan 1, 1970
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT)
getUTCDate() Returns the day of the month from a Date object according to universal time (from 1-31)
getUTCDay() Returns the day of the week from a Date object according to universal time (from 0-6)
getUTCMonth() Returns the month from a Date object according to universal time (from 0-11)
getUTCFullYear() Returns the four-digit year from a Date object according to universal time
getUTCHours() Returns the hour of a Date object according to universal time (from 0-23)
getUTCMinutes() Returns the minutes of a Date object according to universal time (from 0-59)
getUTCSeconds() Returns the seconds of a Date object according to universal time (from 0-59)
getUTCMilliseconds()Returns the milliseconds of a Date object according to universal time (from 0-999)
parse() Takes a date string and returns the number of milliseconds since midnight of January 1, 1970
setDate() Sets the day of the month in a Date object (from 1-31)
setFullYear() Sets the year in a Date object (four digits)
setHours() Sets the hour in a Date object (from 0-23)
setMilliseconds() Sets the milliseconds in a Date object (from 0-999)
setMinutes() Set the minutes in a Date object (from 0-59)
setMonth() Sets the month in a Date object (from 0-11)
setSeconds() Sets the seconds in a Date object (from 0-59)
setTime() Calculates time adding or subtracting a number of milliseconds from midnight January 1, 1970
setUTCDate() Sets the day of the month in a Date object according to universal time (from 1-31)
setUTCMonth() Sets the month in a Date object according to universal time (from 0-11)
setUTCFullYear() Sets the year in a Date object according to universal time (four digits)
setUTCHours() Sets the hour in a Date object according to universal time (from 0-23)
setUTCMinutes() Set the minutes in a Date object according to universal time (from 0-59)
setUTCSeconds() Set the seconds in a Date object according to universal time (from 0-59)
setUTCMilliseconds()Sets the milliseconds in a Date object according to universal time (from 0-999)
toDateString() Returns the date portion of a Date object in readable form
toGMTString() Converts a Date object, according to Greenwich time, to a string. Use toUTCString() instead !!
toLocaleDateString()Converts a Date object, according to local time, to a string and returns the date portion
toLocaleTimeString()Converts a Date object, according to local time, to a string and returns the time portion
toLocaleString() Converts a Date object, according to local time, to a string
toSource() Represents the source code of an object
toString() Converts a Date object to a string
toTimeString() Returns the time portion of a Date object in readable form
toUTCString() Converts a Date object, according to universal time, to a string
UTC() Takes a date and returns the number of milliseconds since midnight of January 1, 1970
valueOf() Returns the primitive value of a Date object

No comments:

Post a Comment