typescript moment to date code example

Example 1: moment to javascript date

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

Example 2: moment js print date

moment(testDate).format('MM/DD/YYYY');

Example 3: typescript get the time moment

/* Here you are assigning an instance of momentjs to CurrentDate: */
var CurrentDate = moment();

/* Here just a string, the result from default formatting 
of a momentjs instance: */
var CurrentDate = moment().format();

/* And here the number of seconds since january of... well, unix timestamp: */
var CurrentDate = moment().unix();

/* And here another string as ISO 8601 
(What's the difference between ISO 8601 and RFC 3339 Date Formats?): */
var CurrentDate = moment().toISOString();

/* And this can be done too: */
var a = moment();
var b = moment(a.toISOString());

console.log(a.isSame(b)); // true

Tags:

Misc Example