-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
new Date() bug #15819
Comments
Are you using the Chrome debugger? (Make sure you aren't using it for Date-related operations, V8 is different from JSC.) |
yes i'm using chrome debugger on emulator. i have fixed it by declaring the new Date as: const dataInicio = new Date( However it`s funny that it works on emulator but not on device |
Can you try disabling the Chrome debugger? |
For me helped this: |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Same. Trying |
We've faced the same problem.
|
I ended up with a slight modification of @SahRckr's method to handle UTC dates. This handles the format
|
@connorpaulstauffer Thanks a ton! This immediately solved my problem! |
If your dates are in UTC an alternative is to remove the
This works because JSCore correctly parses dates in the ISO 8601 format. |
I am facing another weird problem with new Date() in some android devices only, not in iOS. Suppose current time in my phone is 11:55 AM (GMT+5:30). Initially new Date( ).getMinutes() returns correct minutes (55 in this case), but when I go to Date & Time Settings in my Phone and change the time zone to GMT-04:00 (2:26 AM) ,I still get the old time in console (Reactotron console). Restarting the phone apparently seem to fix this bug. Please note that I am not using chrome debugging for logging current time. I am using Reactotron for logging. I am using RN 0.55.4 and android device MI Redmi 4. But this is happening on Samsung devices as well. I have tried using moment also but that too didn't help. I don't want to write a native module for such a trivial task Anyone else facing same problem? |
I suggest this:
JSCore is not native to Android, It's highly likely that the rebuilding might fix your problem. |
@SahRckr Rebuilding might solve the problem but I cannot rebuild the application. I am developing a feature in which if time on user's device is incorrect (Criteria is if the time difference between mobile device time & time sent from server is more than 15 minutes),then I redirect him to Date & Time Settings in Android |
Beautiful! Thank you! My database had many 3 letter time endings so I used substring(0,str.length-4) instead of .replace(' UTC','') |
@SahRckr thank you so much mate, i had no idea that JavaScriptCore is causing this problem. your solution was a good fix. thanks for sharing. |
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
No
Environment
react-native -v
:react-native-cli: 2.0.1
react-native: 0.46.4
node -v
: v7.10.0npm -v
: 4.2.0yarn --version
:Then, specify:
Steps to Reproduce
Not sure if it's a react-native issue or iOS, but i'm setting a new Date('string') -the string comes from the server- and it converts to a Date on iOS emulator, however when I run on device it becomes an invalid date (as I console logged on xCode).
here the logs:
the log scheme: console.log('string identifier', 'new Date(string)', date string from server);
log commands:
console.log('dtini', dataInicio, this.props.programacaoLazer[i].data_inicio);
console.log('dtfim', dataFim, this.props.programacaoLazer[i].data_fim);
console.log('dtselec', this.state.dataSelecionada);
log on emulator:
dtini Tue Sep 05 2017 10:40:00 GMT-0300 (-03) 2017-09-05 10:40:00
dtfim Tue Sep 26 2017 13:18:00 GMT-0300 (-03) 2017-09-26 13:18:00
dtselec Tue Sep 05 2017 15:29:06 GMT-0300 (-03)
log on Xcode running on device:
2017-09-05 15:21:50.326 [info][tid:com.facebook.react.JavaScript] 'dtini', Invalid Date, '2017-09-05 10:40:00'
2017-09-05 15:21:50.326 [info][tid:com.facebook.react.JavaScript] 'dtfim', Invalid Date, '2017-09-26 13:18:00'
2017-09-05 15:21:50.327 [info][tid:com.facebook.react.JavaScript] 'dtselec', Tue Sep 05 2017 15:18:37 GMT-0300 (-03)
The text was updated successfully, but these errors were encountered: