Javascript Data Type How to - Convert date as '26-02-2012' to timestamp








Question

We would like to know how to convert date as '26-02-2012' to timestamp.

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
<!--   w  ww.  ja v a2s  .  c  o  m-->
    var myDate="26-02-2012";
    myDate=myDate.split("-");
    var newDate=myDate[1]+"/"+myDate[0]+"/"+myDate[2];
    document.writeln(new Date(newDate).getTime());

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

The code above is rendered as follows: