Javascript Data Type How to - Parse date in format of 'Sunday, February 14th 2010, 3:25:50 pm'








Question

We would like to know how to parse date in format of 'Sunday, February 14th 2010, 3:25:50 pm'.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.js"></script>
</head><!--  w w  w.  j  av  a 2  s  .  c  o  m-->
<body>
<script type='text/javascript'>
var day= "Sunday, February 14th 2010, 3:25:50 pm";
var valid=moment(day,"dddd, MMMM D[th] YYYY, h:mm:ss a").isValid();
document.writeln(valid);

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

The code above is rendered as follows: