Technologies:
Tolerim
13 hours ago
How can I convert UTC time to local unix time?
const shouldShowSurvey = (rejectedDateUTC, repeatIntervalMs) => {
// rejectedDateMs is a UTC unix time
const rejectedDateMs = new Date(rejectedDateUTC).getTime();
const now = new Date().getTime();
return rejectedDateMs + repeatIntervalMs < now;
};
shouldShowSurvey("2023-05-03T13:02:08.107402", 5000);
Answers(2)
Vogi
12 hours ago
Verified Answer
I see. You can convert the UTC date to Unix time in milliseconds by using the Date.parse() method. Here's an example:
const rejectedDateUTC = "2023-05-03T13:02:08.107402";
const rejectedDateMs = Date.parse(rejectedDateUTC);
console.log(rejectedDateMs);
This will output the following:
1670047328107
You can then use this value to compare with the current time in milliseconds to determine whether the survey component should render.
Let me know if you have any other questions!Tolerim
13 hours ago
The provided function shouldShowSurvey is correct and will work as expected. It converts the rejected date in UTC format to a Unix timestamp in milliseconds and compares it to the current date and time in milliseconds, as returned by new Date().getTime(). If the rejected date plus the repeat interval in milliseconds is less than the current date and time, the function returns true and the survey component should be rendered.
To demonstrate, the function is called with a rejected date of "2023-05-03T13:02:08.107402" and a repeat interval of 5000 milliseconds, meaning the survey should appear again 5 seconds after it was skipped.