Javascript Data Type How to - Convert date format from JSON








Question

We would like to know how to convert date format from JSON.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from w  ww  . ja  v a  2s . c  o m-->
<body>
  <script>
    var d = new Date('14-Jan-14');
    var curr_date = d.getDate();
    var curr_month = ("0" + (d.getMonth() + 1)).slice(-2);
    var curr_year = d.getFullYear();
    document.write(curr_year + "-" + curr_month + "-" + curr_date);
</script>
</body>
</html>

The code above is rendered as follows: