javascript - .tz() in moment.js timezone does not convert time zones correctly -
i having trouble when converting time zone time zone using moment.js.
this code:
convertselectedtimezonetoclients() { let timezoneinfo = { userstimezone: this.$rootscope.mtz.tz.guess(), utcoffset: this.formdata.timezone.offset, selecteddatetime: this.tojsonlocal(this.formdata.sessiondate) + " " + this.formdata.sessiontime }; let utctime = this.$rootscope.mtz.utc(timezoneinfo.selecteddatetime).utcoffset(timezoneinfo.utcoffset).format("yyyy-mm-dd hh:mm"); let con = this.$rootscope.mtz.tz(utctime, timezoneinfo.userstimezone).format(); return con; }
the user picks date, time , time zone drop downs on client page. in timezoneinfo object storing userstimezone (i want able convert timezone user selected on page , convert local time zone).
for example user picks: 11/08/2016 01:30 , utc+2 timezone , timezone utc+1, want show him in label: 11/08/2016 00:30 since utc+1 -1 hour comparing utc+2 timezone.
i store offsets time zones in 1 object , values hard coded (utcoffset: this.formdata.timezone.offset
). before convert time form time zone time zone this: time zone -> convert utc time -> convert user time zone.
what happening utctime variable has correct value. when pass value , users time zone .tz() function , using format() readable value same time utctime shown in picture:
i have read moment.js docs , them .tz().format() should work, can see result is: 2016-11-08t23:30:00+01:00. gets should incremented 1 hour how accomplish get: 2016-11-09t00:30 instead?
i have tried .format("yyyy-mm-dd hh:mm") same problem. when use .local() function should convert utc time specified time zone same problem present.
am getting wrongly? pretty sure when convert 2016-11-08t23:30 utc utc+1 should 2016-11-09t00:30, or 1 hour forward. sees strange in code?
Comments
Post a Comment