React-Native Moment returns wrong day

Asked

Viewed 567 times

2

I’m using Moment in a project with React Native.

And a specific date it does not return the correct day, all the others returns right. I put it in the index.js of the application to see if any instance somewhere was not getting in the way, but still it returns wrong.

import { AppSrc } from './src/containers/App';
import moment from 'moment';

const day = moment('2019-02-17', 'YYYY-MM-DD').format('DD');
console.log('-> MOMENT -> INDEX', day); // '-> MOMENT -> INDEX', '16'

new AppSrc();

Does anyone have any idea what might be causing this?

UPDATE

solved in this way

import moment from 'moment';
import 'moment-timezone';
import 'moment/locale/pt-br';

moment.tz.setDefault('UTC');
moment.locale('pt-BR');

1 answer

1

  • It didn’t work, apparently it’s a Timezone problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.