moment get current date time 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: 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 3: moment to javascript date

let now = moment()
let now = now.toDate()

Example 4: how to get current time using moment

var startDate = moment().subtract(1, 'days'); //one day before the current time