Reputation: 4728
When I invoke the following code
moment('2020-01-01T00:00:00Z').endOf('month').utc().format()
I get the result
'2020-01-01T07:59:59Z'
when I would have expected to see
'2020-01-31T23:59:59Z'
Is this a bug or am I not using the API correctly?
Upvotes: 2
Views: 84
Reputation: 740
I think the problem is you used endOf
before you convert the Date in UTC.
You pass this Date : 2020-01-01T00:00:00Z
but the browser understand it with your timezone so the "real date" is 2019-12-31T15:00:00Z
.
So you must convert it to UTC first and then proceed your change/call/etc.
So, I tried that and it worked ! Tell me if the problem persist.
moment('2020-01-01T00:00:00Z').utc().endOf('month').format()
Upvotes: 2