toLocaleString wrong format on Android
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS Mojave 10.14.1 Node: v11.1.0 Yarn: 1.12.3 npm: 6.4.1 Watchman: 4.9.0 Xcode: Xcode 10.0 Build version 10A255 Android Studio: 3.1.3 Build #AI-173.4819257
Packages: (wanted => installed) react: 16.4.1 => 16.4.1 react-native: 0.56.0 => 0.56.0
Target Platform: Android (8.0)
Steps to Reproduce
- Open a fresh React Native project
- Make sure you’re not debugging JS remotely
- Try to use toLocaleString on a Date() object
let formatted = new Date('2017-11-17T10:59:30.527Z').toLocaleString('de-DE', {
timeZone: 'Europe/Zurich',
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
})
- Either write up a simple component to display text or do an alert/console.log with the aforementioned variable.
Expected Behavior
The expected string should be as follows:
Imput: 2017-11-17T10:59:30.527Z -> Output: 17.11.2017, 11:59
Actual Behavior
The resulting string is as follows:
Imput: 2017-11-17T10:59:30.527Z -> Output: Fri Nov 17 11:59:30 2017
My contention is that this is an issue with the underlying JS engine that Android uses, and handles it differently as opposed to the integrated JS engine on iOS, hence the variance in the date format. For this reason if you open a remote debugged, say on Chrome, you will actually get the correct format, due to the different JS engine handling it, but if you switch off the debugger and resume using the application whilst not debugging remotely, the incorrect format will be shown.
Reproducible Demo
Here’s an example Expo project that shows the behaviour, toggle between iOS and Android to see the difference in the output.
https://snack.expo.io/Bk3unwhyM
EDIT: Updated environment in which this is still reproducible.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:25
- Comments:18 (1 by maintainers)
Top GitHub Comments
This issue must exist.
Issue still present in the latest version.