Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to timezone returning a diffrent value from moment-timzone. #7

Open
emersonbroga opened this issue Feb 11, 2019 · 2 comments
Open

Comments

@emersonbroga
Copy link

Hi Guys,

I'm currently replacing moment-js with date-fns, but when it comes to timezone, I'm unable to get the same value.

Do you guys know what am I doing wrong?

const moment = require('moment-timezone');
const dateFNS = require('date-fns');
const dateFNSTimezone =  require('date-fns-timezone');

const { format } = dateFNS;
const { convertToTimeZone } = dateFNSTimezone;
  
const TZ = 'America/Los_Angeles';

const a = moment().tz(TZ).format();

const b = format(convertToTimeZone(new Date(), { timeZone: TZ }), 'YYYY-MM-DDTHH:mm:ssZ');

console.log(a); // 2019-02-11T09:28:29-08:00
console.log(b); // 2019-02-11T09:28:29-02:00

if you notice the values are equal, execept the last part, where moment gives -08:00 but date-fns-timezone returns -02:00

@Ben-Davis1
Copy link

Hey @emersonbroga, is the local timezone of your system -02:00?

@LavaGolem
Copy link

Hey, I'm having similarish issue. I use convertToTimeZone, but only the time is shifted, the timezone stays the sam (my system timezone)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants