Javascript Date Object

Updated on 20 Mar 2012,
Published on 20 Mar 2008

Javascript Date Object also supports Date Time functions and provides number of functions to perform Date Time comparisons, retrieving current date or time, manipulating date time output.

In JavaScript you can use Date object to perform different actions on Date Time functions. As you know JavaScript is a client end script so it performs function execution at client end. JavaScript Date object also works at client end and retrieves the date and time of the computer system where the web page is being browsed.

JavaScript Data Object Examples:

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

Retrieve Current Date Time using JavaScript

JavaScript Date object can be used directly to get the current Date Time of the system.

Syntax

Date();

Example

document.write(Date());

To work with various function of Date object you can define a variable for Date object using new keyword.

Example

var myDate = new Date();

document.write(myDate);

JavaScript Example to get current Date String Format

document.write(myDate.toDateString());

JavaScript Example to get current Time String Format

document.write(myDate.toTimeString());

JavaScript Example to retireve Local Date String Format

document.write(myDate.toLocaleDateString());

JavaScript Example to retrieve Local Time String Format

document.write(myDate.toLocaleTimeString());

Output:

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

Date and Time Functions

Continue to next tutorial: JavaScript Date functions to learn Date functions provided by Javascript date object.

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