diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index 7cf7c34be..4e494d31c 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -54,7 +54,7 @@ export default (o, c, d) => { const proto = c.prototype proto.tz = function (timezone) { const target = this.toDate().toLocaleString('en-US', { timeZone: timezone }) - const diff = (this.toDate() - new Date(target)) / 1000 / 60 + const diff = Math.round((this.toDate() - new Date(target)) / 1000 / 60) return d(target).utcOffset(localUtcOffset - diff, true) } d.tz = function (input, timezone) { diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js index 3411bb7f4..a8c02ed32 100644 --- a/test/plugin/timezone.test.js +++ b/test/plugin/timezone.test.js @@ -77,6 +77,13 @@ describe('Convert', () => { expect(dec.tz('Australia/Sydney').format('ha')).toBe('11pm') }) }) + + it('format Z', () => { + [dayjs, moment].forEach((_) => { + const losAngeles = _('2020-08-06T03:48:10.258Z').tz('Asia/Tokyo') + expect(losAngeles.format('Z')).toBe('+09:00') + }) + }) })