admin管理员组文章数量:1307840
I am using react native to develop an app that fetches usage time from third party apps in device. I am fetching usage time from midnight 12am to current time. But the usage time I got is a bug. The following is my code section where I set the start time to midnight 12 am and end date to current time
const startDate = new Date();
startDate.setUTCHours(18,15,0,0); // Set to midnight in UTC
startDate.setUTCDate(startDate.getUTCDate() - 1);//This is used to set date to previous day as I am currently in Nepal and NST is UTC+5:45
const endDate= new Date().
I am using @brighthustle/react-native-usage-stats-manager package. The usage time I received is far from similar to digital wellbeing. Is there some issue fetching the local time of device?
I am using react native to develop an app that fetches usage time from third party apps in device. I am fetching usage time from midnight 12am to current time. But the usage time I got is a bug. The following is my code section where I set the start time to midnight 12 am and end date to current time
const startDate = new Date();
startDate.setUTCHours(18,15,0,0); // Set to midnight in UTC
startDate.setUTCDate(startDate.getUTCDate() - 1);//This is used to set date to previous day as I am currently in Nepal and NST is UTC+5:45
const endDate= new Date().
I am using @brighthustle/react-native-usage-stats-manager package. The usage time I received is far from similar to digital wellbeing. Is there some issue fetching the local time of device?
Share Improve this question edited Feb 3 at 12:43 Susav Karki asked Feb 3 at 12:42 Susav KarkiSusav Karki 11 bronze badge1 Answer
Reset to default 1Well, as far as I can see it looks like the issue might be related to how you're setting the time and handling time zone offsets. Like you're working with Nepal Standard Time (NST, UTC+5:45), but using UTC methods (setUTCHours, setUTCDate), the conversion could be causing discrepancies in the times you're calculating.
Try this:
const startDate = new Date();
startDate.setUTCHours(18,15,0,0); // Set to midnight in UTC
startDate.setUTCDate(startDate.getUTCDate() - 1); // This is used to set date to previous day as I am in Nepal and NST is UTC+5:45
const endDate = new Date();
本文标签: androidI get bug when I access Local timereact nativeStack Overflow
版权声明:本文标题:android - I get bug when I access Local time - react native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741820870a2399355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论