I have a date represented as a string:
const dateStr = "2022-09-29T00:00:00Z";
So this is UTC format with zero (equivalent to "2022-09-29T00:00:00+0000"
)
When I use momentJS it is converted to my local time(and this is fine), but my local time -3 hours, so by this example I have 22-09-28
, this happens because momentJs doesn't recognize it as UTC, but it is UTC format - why?
Please see the screenshot attached below, I mean _isUTC
flag
Code I am testing below:
const dateStr = "2022-09-29T00:00:00Z";
const res = moment(dateStr)
const res1 = moment(dateStr).format('YYYY-MM-DD'); // will be 2022-09-28 because of -3 hours my timezone and it is not detected as UTC.
console.log(res);
P.S. I know that moment(dateStr).utc().format('YYYY-MM-DD')
will work but can it be detected automatically?