Reputation: 49
My current timezone is GMT+1. Lately, i noticed sometimes i was getting -60 value where as other time i had 0.
componentDidMount() {
this.props.screenProps.showToast(new Date().getTimezoneOffset(), 1);
}
Now i realize it happens when i am debugging it on chrome that i get the correct timezone and whenever i turn off the remote debugging in chrome i get the offset value of 0.
It seems that the Date() object is being manipulated differently depending on the environment.
The device that i am testing this is android. Also, would it be any different on ios?
Any clarification on this would be really helpful.
Upvotes: 1
Views: 1160
Reputation: 324
Try to display just the current time. If it still dispays a wrong time, then the issue is with the JS engine those simulators are running. Try moment JS or any other light weight time libraries if they work for your case.
Upvotes: 0
Reputation: 8841
I think this may have something to do with what you are experiencing.
JavaScript Runtime When using React Native, you’re going to be running your JavaScript code in two environments: On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn’t use JIT due to the absence of writable executable memory in iOS apps. When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
I think this is leading to the inconsistency when remote debugging is off/on. Find more info here.
Upvotes: 3