Moment JS

Example of parsing and formatting a Date with Moment JS.

by Luiza CICONE

HTML

<script src="http://momentjs.com/downloads/moment.js"></script>

JavaScript

var expectedValue = new Date(2016, 0, 31, 23, 59, 59, 999); // January 31, 2016 23:59:59
var returnedValue = getMonthEnd(1, 2016);

function getMonthEnd(month, year) {
  return moment({
    year: year,
    month: month - 1
  }).endOf('month').toDate();
}

console.log(expectedValue.getTime())
console.log(returnedValue.getTime())