The primary issue you are facing stems from the interpretation of your input string as being associated with the local time zone, leading to discrepancies due to different time zones on the two machines used for testing. One machine undergoes a DST transition between the dates in question, resulting in a one-hour difference compared to the other machine.
Your machine displays timestamps that are 8 hours ahead of UTC (UTC+8) for both instances, indicative of regions like China, Western Australia, and Irkutsk Russia that operate on UTC+8 without observing DST. Conversely, your friend's machine shows timestamps 2 hours ahead of UTC (UTC+2) on one date and 3 hours ahead on another date, suggesting a non-standard time zone setting or outdated time zone data updates.
It is important to note that the input string format 2022-04-01 00:00:00
deviates from the standard date-time string format defined by the ECMAScript specification, posing inconsistencies in parsing across browsers. For uniform interpretation across browsers, consider formats such as 2044-04-01T00:00:00
for local time, 2044-04-01T00:00:00Z
for UTC, or 2044-04-01T00:00:00+08:00
for a specific time zone offset.
If retaining the original format is essential, avoid using the Date
object for parsing; opt for libraries like Luxon or date-fns, or employ regex and string manipulation methods for custom parsing.