React-Native reacts differently when not debugging remotely

<Text style={s.date}>{ new Date(this.props.order.ordered_at).toLocaleDateString('en-US', { day: '2-digit', month: 'short' }) }</Text>
<Text style={s.time}>({ new Date(this.props.order.ordered_at).toLocaleTimeString('en-US', { hour: '2-digit', minute:'2-digit', hour12: true }) })</Text>

Output when JS remote debugging is disabled

02/13/17 (23:51:31)
02/13/17 (23:48:07)

Output when JS remote debugging is enabled

Feb 13 (11:51 PM)
Feb 13 (11:48 PM)

What causes this and how to fix it?

+4
source share
1 answer
import moment from 'moment';

<Text style={s.date}>{ moment(new Date(this.props.order.ordered_at)).format('ll') }</Text>
<Text style={s.time}>{ moment(new Date(this.props.order.ordered_at)).format('LT') }</Text>

will give consistently

Feb 13, 2017 (11:51 PM)
Feb 13, 2017 (11:48 PM)

Why Date()doesn't the usual way work?

JavaScript Runtime When using React Native, you will run your JavaScript code in two environments:

  • iOS- , Android React Native JavaScriptCore, JavaScript, . iOS JSC JIT - iOS.
  • Chrome JavaScript Chrome WebSocket. V8.

, . , , JS , .

, , momentJS , JS , , docs

+7

Source: https://habr.com/ru/post/1669656/


All Articles