I am currently facing an issue with my application where I need to ensure that it always uses UTC time, regardless of the system time. I have a method in place to create a date:
public static createDate(date: Date = new Date()): Date {
return new Date(
Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDay(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
date.getUTCMilliseconds()
)
);
}
Despite this method, when the time is saved in the database, it appears to be 8 hours ahead and I'm unsure why this discrepancy is occurring.
I have attempted other solutions found on platforms like stack overflow, including using libraries such as moment and date-fns, but unfortunately, none of these alternatives have resolved the issue so far.