'Formatted date as String converted to date wrong
I am trying to store date in DB using the current timezone.
I have used library date-fns-tz When I convert the date as a string is okay, but when I want to create that string as a Date it is still a problem.
const date = new Date();
const date_string = formatInTimeZone(
date,
"Europe/Rome",
"yyyy-MM-dd HH:mm:ss"
);
console.log(date_string); //2022-04-16 11:46:28 (Right time)
const current_date = new Date(date_string); // 2022-04-16T09:46:28.000Z (Converted to 2h back)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
