Even the value I set for the time in the moment.js timezones same following two different approaches the value of the date returned is different
moment("02:00","HH:mm").tz('America/Chicago').format()returns 2022-03-31T15:30:00-05:00
moment().tz('America/Chicago').set({hour:"02",minute:"00"})returns 2022-04-01T02:00:02-05:00
Can anyone please help me in understanding why is it so?
console.log(moment("02:00","HH:mm").tz('America/Chicago').format());
console.log(moment().tz('America/Chicago').set({hour:"02",minute:"00"}).format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data-10-year-range.js"></script>
You have different approach with two examples:
In first example you do:
2021-04-01 12:15)2021-04-01 02:00)+02:00 tz to -05:00 - moves back by 7 hours) (2021-03-31 15:00)While in second example you do:
2021-04-01 12:15)2021-04-01 06:15)02:00 (2021-04-01 02:00)