Javascript Data Type How to - Convert UTC value in dd-mm-yyyy format








Question

We would like to know how to convert UTC value in dd-mm-yyyy format.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.js"></script>
<!--from ww  w .j a va2 s.  c  om-->
</head>
<body>
<script type='text/javascript'>

document.writeln(new Date());
document.writeln("<br/>");
document.writeln(moment().format("D-M-YY"));
document.writeln("<br/>");
document.writeln(moment(1367214805 * 1000).format("D-M-YY"));

</script>
</body>
</html>

The code above is rendered as follows: