[英]react-native-modal-datetime-picker issue with daylight saving time zone
I have been using react-native-modal-datetime-picker package for my react native mobile application and came across an issue.我一直在为我的react native 移动应用程序使用react-native-modal-datetime-picker包,但遇到了一个问题。
In the date picker I need to have a default selected date as '1985-08-17'
and when the time zone is America/Mexico_City (-05:00)
the default selected date becomes the previous day which is '1985-08-16'
.在日期选择器中,我需要将默认选定日期设为
'1985-08-17'
,当时区为America/Mexico_City (-05:00)
,默认选定日期变为前一天,即'1985-08-16'
。
Is there any thing that I have done wrong in the below code sample?我在下面的代码示例中做错了什么吗?
<DateTimePicker
isVisible={true}
date={new Date('1985-01-17')}
onConfirm={()=>()}
onCancel={()=>()}
mode={'date'}
/>
In the same CDT time zone when I change the device timezone to America/Chicago
this issue is not reproducible.在相同的 CDT 时区,当我将设备时区更改为
America/Chicago
时,此问题不可重现。
I just ran into this as well.我也刚碰到这个。 The reason for it is because react-native-modal-datetime-picker is using your local timezone, whereas
new Date(...)
uses UTC .原因是 react-native-modal-datetime-picker 使用的是您的本地时区,而
new Date(...)
使用的是UTC 。
You can fix it by telling react-native-modal-datetime-picker to use UTC as well like this您可以通过告诉 react-native-modal-datetime-picker 像这样使用 UTC 来修复它
<DateTimePicker
isVisible={true}
date={new Date('1985-01-17')}
onConfirm={()=>()}
onCancel={()=>()}
mode={'date'}
timeZoneOffsetInMinutes={0}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.