JavaScript Date functions

Updated on 20 Mar 2012,
Published on 20 Mar 2008

JavaScript Date object can also be used to get the Date parts or Time parts. To get the date, day, month and year separately you have to define the Date object with new keyword. This will provide you various functions to get the Date and Time in JavaScript.

JavaScript Data Object Examples:

You can see the live samples and examples of JavaScript Data Object from the following links:

JavaScript Date Object Methods to get date parts

getDate()
getDate function returns the current date from 1 to 31 according to the corresponding month.

getDay()
getDay function returns the current Day of the week from 0 to 6 where 0 for Sunday, 1 for Monday and so on.

getMonth()
getMonth function returns the current month from 0 to 11 where 0 for January, 1 for February and so on.

getFullYear()
getFullYear function returns the current year e.g. 2008

JavaScript Examples to get the parts of Date

// Date object defined with new keyword.
var myDate = new Date();

//  javaScript getDate function
document.write(myDate.getDate());

//  javaScript getDay function
document.write(myDate.getDay());

//  javaScript getMonth function
document.write(myDate.getMonth());

//  javaScript getFullYear function
document.write(myDate.getFullYear());

Output:

You can see the output of above discussed code from the following link:

Date Functions

Continue to next tutorial: JavaScript Date Object Time functions to learn Time functions provided by Javascript Date Object.

0 Responses to "JavaScript Date functions"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers