react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Android treating DateTime strings without timezone information as UTC. iOS treats as Local.

Open badbod99 opened this issue 3 years ago • 3 comments

Description

When creating a DateTime object using a string without timezone information (e.g. taking a user entered date and/or time), Android treats the passed string as UTC, iOS treats the passed string as local. This results in difficulty managing user entered dates and times consistently between platforms.

This works correctly in a Web Browser on both Android and iOS devices.

Same issue occurs when using other timezones (e.g. IST, +5.30). Android treats the DateTime string as UTC, iOS treats the string as local.

Devices tested with

iPhone 12 (iOS 14) Huawei P20 Pro (Android 10)

React Native version:

System: OS: Windows 10 10.0.19041 CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz Memory: 3.63 GB / 15.92 GB Binaries: Node: 14.15.2 - C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 6.14.9 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: 16.8.31019.35 (Visual Studio Professional 2019), 15.9.28307.812 (Visual Studio Professional 2017) Languages: Java: Not Found Python: 3.9.1 npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Use an Android device with timezone set to BST (British Summer Time).
  2. Create a simple DateTime object with a date time string without timezone information within summer time (e.g. 2021-06-05T13:55)
  3. Show the date using .toISOString().
  4. Perform the same steps on Apple iPhone device.

Expected Results

Created DateTime object to represent passed DateTime string as local on both Android and iOS. This is the same as JavaScript handles these strings in the browser (Chrome on Android, Safari on iOS).

Actual Results

Created DateTime object on Android treats passed value as UTC. I.e. 2021-06-05T13:55:00.000Z Created DateTime object on iPhone treats passed value as Local (BST). I.e. 2021-06-05T12:55:00.000Z

Created

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@badbod99/petrified-bananas

badbod99 avatar May 05 '21 15:05 badbod99

Duplicate of https://github.com/facebook/react-native/issues/30245

ravirajn22 avatar May 20 '21 12:05 ravirajn22

@ravirajn22 - I don't think this is a duplicate really. That issue has been closed without any resolution. As mentioned in my issue above, this works correctly on the web browser on both iOS and Android, but not in React Native, so this is something wrong with React Native javascript usage for Android.

badbod99 avatar Jun 14 '21 12:06 badbod99

ooop c, Android working, not IOS new Date().toLocaleString('en-NZ', { timeZone: 'Pacific/Auckland' }

JerryHuang2015 avatar Oct 17 '22 20:10 JerryHuang2015