Roei Grinshpan
Roei Grinshpan

Reputation: 453

Moment js get wrong time when add days

I using moment JS

my time now is 12/01/2020 17:30

  1. when I console log : moment().format("LLL"); I get the right hour and date 1 December 2020 17:30
  2. when I console log : moment().add(0, "days"); I get wrong hour "2020-12-06T15:30:52.046Z"

why is it ? and how can I declare globally to set the right time of my country (im in jerusalem its +02:00 gmt)

my global config is :

moment.updateLocale("he", {
weekdays: ["ראשון", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת"],
longDateFormat: {
    LT: "HH:mm",
    LTS: "HH:mm:ss",
    L: "DD/MM/YYYY",
    LL: "D MMMM YYYY",
    LLL: "D MMMM YYYY HH:mm",
    LLLL: "dddd D MMMM YYYY HH:mm",
},
});

Upvotes: 0

Views: 597

Answers (1)

Hakier
Hakier

Reputation: 505

Everything is fine but in the first example you use format to display a formatted time but in second you are not using format.

Try it like so: moment().add(0, "days").format("LLL"); and it will work.

2020-12-06T15:30:52.046Z Is a time and date format that date is using to calculate local time for specific time zone.

Upvotes: 1

Related Questions