Moment.js locally until I specify the format

I need to set the default value to the datetime-localcurrent local time. Native JS seems to print in local time by default:

new Date($.now()); // "Sat Nov 12 2016 22:36:52 GMT+1100 (AEDT)"

However, features like these toISOString()are displayed in UTC, and although I can locally pull out individual components, I don’t really want to play with the add-on, etc. So I am trying to use this with moment.js:

moment().local().format(); // "2016-11-12T22:34:05+11:00"

Cool! Now I just need to set the format to a small bit:

moment().local().format('YYYY-MM-DThh:mm'); // "2016-11-12T10:39"

Waaaaaaait. Now it is in UTC again, although I indicated local.

In this particular case, I could use string manipulations to just drop the end to pick a date, but of course I'm going to reach the point where I want to print local time in an arbitrary format. Did I miss something?

+4
1

- UTC, 12h.

hh= 12h, hh= 24h. :

moment().local().format('YYYY-MM-DTHH:mm')
+5

Source: https://habr.com/ru/post/1660570/


All Articles