Wrong timezone in some devices - React Native

Viewed 2603

I have a react-native app running on various devices. Wherever I use time or datetime from new Date() or moment or by any other library, some devices show wrong time in the app. The actual device time is correct with respect to timezone but it shows a different time inside the app with a different timezone even if the timezone settings in the device is correctly set (Tried with Automatic and Manually set timezone).

I came across similar issues on stackoverflow and react-native's git issues stating that it can be fixed by updating jsc-android package manually. I already have the latest version of jsc-android in the app, but then too facing the same problem. This occurs even on latest version of react-native: 0.61 too.

One of those devices are Redmi Note 5 (Android version 8.1.0).

Here is a screenshot of a sample app(Please ignore the orange stripes) showing incorrect timezone. The actual timezone is IST(Indian Standard Time)

Screenshot

You can compare the system time in the Status Bar(11:21 AM) and the App time (3:51 AM).

Here is the code for the above output (App.js)


    import React from 'react';
    import {
      View,
      Text,
      StatusBar,
    } from 'react-native';
    import moment from 'moment';
    
    const App = () => {  
      return (
        <View style={{flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <StatusBar barStyle="dark-content" />
          <Text>Time: {moment(new Date()).format("h:mm A")}</Text>
          <Text>Time String: {new Date().toTimeString()}</Text>
          <Text>Time Offset: {new Date().getTimezoneOffset()}</Text>
          <Text>Static Time (5:21 PM): {moment(new Date("2019-09-23T11:51:29.184Z")).format("h:mm A")}</Text>
        </View>
      );
    };
    
    export default App;

Any Suggestions???

1 Answers
Related