JavaScript tutorial-Date Object

Date Object

JavaScript provides you a Date object with a lot of methods that can be used to manipulate date and time values such as getting and setting date, day, month, year, hour, minute, second, as well as converting date and time values to string values. To create a date object you need to use the new keyword followed the Date().


var mydate=new Date();

This will create a new date object that is set to the current date and time of you local machine. If you want to create a new date object and set it to date and time of own your choice you can supply the date and time values as shown below:

var mydate=new Date("01 January 2012");

This date object will set to the first of January 2012.

Another way to create a date object and initialize date and time values is to supply those values(year, month, day,  hour, minute, second, millisecond) as seen below:

var mydate=new Date(2012,01,01,12,30,20);

The subsequent parts of this topic we will discuss about methods used to work with date and time values.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.