momentjsangular-momentmoment-timezone

Moment toJSON does not consider timezione


I've angular application with moment@2.24.0. I do this simple actions:

 let test = moment('2019112200:00','YYYYMMDDmm:ss');
 console.log(test .toJSON());

the result is

2019-11-21T23:00:00.000Z

i think it doesn't consider timezone. With

moment.locale('it')

the result is the same.

The workaround can be moment.format() but i would use the right solution.

Here fiddle to replicate https://jsfiddle.net/crakdelpol/r6yu2abL/1/


Solution

  • A valid alternative is

    test.ISOString(true)
    

    Result is: 2019-11-22T00:00:00.000+01:00