Momentjs instant object and offset

I have a momentjs object that contains a date and time with an offset. This momentary object was created from its string representation:

var x = moment("2017-02-08T04:11:52+6:00")

After working with the object, I would like to get the same textual representation from the object of the object.

When I try to format the object, I get the following results:

  • x.format() => "2017-02-08T04:11:52+14:00"
  • moment.parseZone(x).format("YYYY-MM-DDTHH:mm:ssZ") => "2017-02-07T14:11:52+00:00"

How can I format my moment object in such a way as to have the same idea again?

+4
source share
1 answer

Few things:

  • , +6:00. ISO8601 . ( +06:00. , .)

  • , , moment(...). x, , , .

  • parseZone , Moment.

  • , , , , , . , , , .

    var str1 = "2017-02-08T04:11:52+06:00";
    var mom = moment.parseZone(str1);
    var str2 = mom.format();  // "2017-02-08T04:11:52+06:00"
    
+4

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


All Articles