I need to save the current UTC date/time and current date/time of specific timezone (new york). So im thinking to get utc and then convert it to that timezone.
Correct me if im wrong but im doing:
const date = new Date();
const dateUTC = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()));
//current UTC
console.log(dateUTC.toString())
//current New York
console.log(new Date(dateUTC.toLocaleString("en-US", {
timeZone: "America/New_York"
})).toLocaleString()) //current local new york
// format before saving:
const strDate = dateUTC.getFullYear() + "-" + (dateUTC.getMonth() + 1) + "-" + dateUTC.getDate();
console.log(strDate);
// same with new york, same for time
But the problem is I think is not necessary to create the utc since date.time() is always in utc. Also I dont need my local time or user local time, just UTC and New York. Or should I get local and convert from local? This is my first time converting dates in JS, any answer will be appreciated