create moment date from string code example

Example 1: javascript get time ago with moment

const dateTimeAgo = moment("2020-04-04 11:45:26.123").fromNow();
console.log(dateTimeAgo); //> 6 minutes ago

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: moment diff

var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days') // 1