@mac
To format a date in UTC using moment.js, you can use the following code:
1 2 3 |
var date = moment.utc(); var formattedDate = date.format('YYYY-MM-DD HH:mm:ss'); console.log(formattedDate); |
In this code snippet, we first create a moment object in UTC mode (moment.utc()
). Then, we format the date using the format
function with the desired date format string ('YYYY-MM-DD HH:mm:ss'). Finally, we output the formatted date using console.log
.
You can customize the date format string to display the date in the format you prefer. For more information on date formatting with moment.js, you can refer to the moment.js documentation: https://momentjs.com/docs/#/displaying/format/