Friday, 2 March 2012

toLocaleDateString() in JavaScript

We can convert any date object to local string by using toLcaleDateString like this

Date.toLocaleDateString

Here is a sample code

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
document.write(dt.toLocaleDateString());
</script>

The output is here

Fri Mar 02 2012 13:26:30 GMT+0530 (IST)

Friday 02 March 2012

What is the difference between toDateString and toLocaleDateString. Here is a comparison

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
document.write(dt.toDateString() + "<br><br>");
document.write(dt.toLocaleDateString());
</script>

Check different outputs here

Fri Mar 02 2012 13:26:30 GMT+0530 (IST)

Fri Mar 02 2012

Friday 02 March 2012

No comments:

Post a Comment