xxxxxxxxxx
const currentDate = moment().format('YYYY-MM-DD');
console.log(currentDate);
xxxxxxxxxx
// using moment()
var now = moment();
let today = now.format('YYYY-MM-DD');
xxxxxxxxxx
// Import the Moment.js library
const moment = require('moment');
// Get the current date
const currentDate = moment().format('YYYY-MM-DD');
// Print the current date
console.log(currentDate);
xxxxxxxxxx
// call this function, passing-in your date
function dateToFromNowDaily( myDate ) {
// get from-now for this date
var fromNow = moment( myDate ).fromNow();
// ensure the date is displayed with today and yesterday
return moment( myDate ).calendar( null, {
// when the date is closer, specify custom values
lastWeek: '[Last] dddd',
lastDay: '[Yesterday]',
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
// when the date is further away, use from-now functionality
sameElse: function () {
return "[" + fromNow + "]";
}
});
}