Javascript Data Type How to - Create a date object from a date-string which contains AM/PM as '1 Jan 2000 8:20:00 PM'








Question

We would like to know how to create a date object from a date-string which contains AM/PM as '1 Jan 2000 8:20:00 PM'.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from www  .ja  v a  2  s.co m-->
<body>
  <script type='text/javascript'>
        var date = new Date('1 Jan 2000 8:20:00 PM');
        console.log(date.getHours());
        document.writeln( date.getHours() );
    </script>
</body>
</html>

The code above is rendered as follows: