Javascript Data Type How to - Convert date format from "yyyy-mm-dd" to "December 11th, 2013"








Question

We would like to know how to convert date format from "yyyy-mm-dd" to "December 11th, 2013".

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
var str_date = "1983-24-12",
    arr_date = str_date.split('-'),
    months   = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
document.writeln(months[arr_date[2]] + ' ' + arr_date[1] + ', ' + arr_date[0]);
</script><!-- w ww. j  a  v  a  2  s .co m-->

</body>
</html>

The code above is rendered as follows: