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();