date to moment code example
Example 1: moment to date
moment().toDate();
Example 2: format a date moment
moment(testDate).format('MM/DD/YYYY');
Example 3: moment format date
moment().format(); // "2019-08-12T17:52:17-05:00" (ISO 8601, no fractional seconds)
moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Monday, August 12th 2019, 5:52:00 pm"
moment().format("ddd, hA"); // "Mon, 5PM"
Example 4: timestamp convert moment vue
var day = moment.unix(1318781876); //seconds
var day = moment(1318781876406); //milliseconds
// and then:
console.log(day.format('dddd MMMM Do YYYY, h:mm:ss a'));
// "Sunday October 16th 2011, 9:17:56 am"
Example 5: moment to javascript date
let now = moment()
let now = now.toDate()
Example 6: moment format date
moment("20111031", "YYYYMMDD").fromNow(); // 9 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 9 years ago
moment().startOf('day').fromNow(); // 12 hours ago
moment().endOf('day').fromNow(); // in 12 hours
moment().startOf('hour').fromNow(); // 26 minutes ago