Obtain the current date or time when an app is running (local or UTC time)
When using moment.js, you can specify the format you’d like the date to be in. For example, the following code would return a date with the years first (4 digit years) then the month and day specified by two digits (eg 2020-03-18)
var date = moment().format('YYYY-MM-DD');
You can find out more about the different options here.
You can also get the time in a similar way to the dates. The following code displays the time with colons separating it eg: 16:20:13
var time = moment().format('HH:MM:SS');
Different display options for time can also be found here.
If you’re working with multiple time-zones you may want to get the UTC rather than a user’s local time. You can do this in the following way:
var timeStamp = moment().toISOString();