Moment.js

node v0.12.18
version: 1.0.0
endpointsharetweet
var moment = require("moment"); function getMonthDateRange(year, month) { var moment = require('moment'); // month in moment is 0 based, so 9 is actually october, subtract 1 to compensate // array is 'year', 'month', 'day', etc var startDate = moment([year, month - 1]); // Clone the value before .endOf() var endDate = moment(startDate).endOf('month'); // just for demonstration: console.log(startDate.toDate()); console.log(endDate.toDate()); // make sure to call toDate() for plain JavaScript date type return { start: startDate, end: endDate }; } getMonthDateRange(2015, 12);
Loading…

no comments

    sign in to comment