英文:
Stange behavior of time in @react-native-community/datetimepicker IOS device
问题
我在使用@react-native-community/datetimepicker的IOS设备上遇到了一个非常奇怪的问题,当使用"TIME"模式时。每当我更改时间,它会自动恢复到实际时间,更改后时间重置。请问我该如何解决这个问题?
注意:这个问题只在IOS设备上出现。
附上快速检查的snack链接:
https://snack.expo.dev/@dedevelopers/date-time-picker-issue
英文:
I am having a very strange issue in the IOS device for @react-native-community/datetimepicker while using "TIME" mode.
Whenever I change the time it automatically reverted back to the actual time, time reset on changing. Can you please guide how I can fix this issue?
NOTE: ITS ONLY HAVING ISSUE WITH IOS DEVICES.
>Attach is the link to the snack so that you can check quickly.
答案1
得分: 1
要保留date
,您需要在onChange
回调函数中更新DatePicker中的当前日期,如下所示:
const onChange = (event, selectedDate) => {
const currentDate = selectedDate;
setDate(new Date(selectedDate));
// 其他操作...
}
您可以检查这个修复的示例,基于您的需求:这里。
英文:
To keep the date
you need to update the current date in the DatePicker in the onChange
callback function like this:
const onChange = (event, selectedDate) => {
const currentDate = selectedDate;
setDate(new Date(selectedDate));
....
}
You can check this fixed snack based on yours from here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论