How to print date in Java Script

Date object enables Java Script programmers to create an object that contains information about a particular date and provides a set of methods to work with that information. To create an instance of the date object, use the keyword new as follows:
var my_date = new Date(parameters);
The parameter, if left empty, indicates today's date & time . The parameter could be any specific date format.

Date object provides the following methods.

getDate( ) : Returns date of the month as an integer from 1 to 31.
setDate( ) : Sets date of the month based on an integer argument from 1 to 31.
getHours( ) : Returns hours as an integer from 0 to 23.
setHours( ) : Sets hours based on an argument from 0 to 23.
getTime( ) : Returns number of milliseconds since 1 feb 2014 at 00:00:00
setTime( ) : Sets time based on an argument representing the number of Milliseconds since 1 feb 2014 at 00:00:00.

Date class gives the current date. You can take Date class object in a single variable like

Var today= new Date();


This object represent the current date. You know very well that every line of code in java script is known as statement. Lets take an simple example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<script type ="text/javascript" >
    var todaydate = new Date();
    document.write("Date is" + todaydate.toString());

</script>
</body>
</html>

Code generate the following output
How to print date in Java Script

How to print date in Java Script How to print date in Java Script Reviewed by Jacob Lefore on April 06, 2015 Rating: 5

No comments