|
| JAVASCRIPT toLocaleString() METHOD
The toLocaleString() method in javascript converts a date object into local date and time and returns the result as a string.
The general format is:
dateObject.toLocaleString(specified date[optional]);
The toLocaleString()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 toLocaleString()method, you will first have to create a new date object and then use the new date object with the toLocaleString()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.toLocaleString()); //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.toLocaleString());
</script>
Will output:
See Also:
|
|