user756659
user756659

Reputation: 3510

Parsing start of day in a different timezone than my device currently is giving unexpected results

I am in the process of moving from moment.js to dayjs.js. I am getting unexpected results in a particular use case.

My device is currently using 'America/New_York' timezone and it is ~ 10/22/2024 @ 12:30AM. Meaning it is still the 21st in Los Angeles.

moment.js :

dateTZ = 'America/Los_Angeles';     
date = moment().tz(dateTZ).startOf('day').format('MMM Do, YYYY [@] h:mm a z');  
console.log(date); // returns 'Oct 21st, 2024 @ 12:00 am PDT' - correct

dayjs.js :

dateTZ = 'America/Los_Angeles'; 
date = dayjs().tz(dateTZ).startOf('day').format('MMM Do, YYYY [@] h:mm a z');   
console.log(date); // returns 'Oct 21st, 2024 @ 6:00 am PDT' - wrong

I've reviewed the dayjs docs and don't see where I am going wrong. Or perhaps this isn't possible with dayjs?

Upvotes: 0

Views: 21

Answers (0)

Related Questions