|
| JAVASCRIPT toString() METHOD
The toString() method in javascript converts a date object into date and time and returns the result as a string.
The general format is:
dateObject.toString(specified date[optional]);
The toString()method takes an optional specified date as parameter. If left out, today's date will be used.
If you want to return the full date/time with the toString()method, you will first have to create a new date object and then use the new date object with the toString()method.
Example 1: Return date/time string as of now.
<script type="text/javascript">
var dd = new Date(); //sets the date/time
document.write (dd.toString()); //outputs the date/time
</script>
Will output:
Example 2: Return date/time string with a specified date/time.
<script type="text/javascript">
var dd = new Date("May 21, 2007 01:15:00");
document.write (dd.toString());
</script>
Will output:
See Also:
|
|