Javascript Data Type How to - Convert a yyyy-mm-dd to other date format








Question

We would like to know how to convert a yyyy-mm-dd to other date format.

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
<!--   ww  w .  j a v  a  2s  .  c o m-->
var str_date = "2015-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>
</body>
</html>

The code above is rendered as follows: