Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Test Page</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  body {
    font-family: sans-serif;
  }
  p {
    margin: 0px;
  }
</style>
</head>
<body>
  <script type='text/javascript'>
    (function() {
      function ddmmyyyyToDate(str) {
          var parts = str.split("-");
          return new Date(parseInt(parts[2], 10),      // Year
                          parseInt(parts[1], 10) - 1,  // Month (starts with 0)
                          parseInt(parts[0], 10));     // Day of month
      }
  
      var s1 = "31/08/2014";          // January 1st 2010
      var d1 = ddmmyyyyToDate(s1);
      display("d1 = " + d1);
      var s2 = "01-02-2010";          // February 1st 2010
      var d2 = ddmmyyyyToDate(s2);
      display("d2 = " + d2);
      var diff = d2 - d1;
      display("Difference is " + diff);
      
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = msg;
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers