maurogestoso
10/16/2017 - 11:46 AM

medium-momentjs-manipulate.js

const myNiceFormat = 'ddd MMM Do, YYYY';

// create a new date object representing today
const today = moment();
console.log(today.format(myNiceFormat));  // Mon Oct 16th, 2017

// calculate the scheduled day
const scheduledDate = moment().add(20, 'days');
console.log(scheduledDate.format(myNiceFormat));  // Sun Nov 5th, 2017

// calculate the start of the month
const startOfMonth = moment().startOf('month');
console.log(startOfMonth.format(myNiceFormat));  // Sun Oct 1st, 2017

// offset to Tokyo time
const tokyoTime = moment().utcOffset(9);
console.log(tokyoTime.toString());  // Mon Oct 16 2017 20:53:39 GMT+0900