Reputation: 16002
I was expecting the following to return 2020-01-01T23:59:59
But due to my time zone being GMT+2, it results in this 2020-01-01T21:59:59.
How do I represent the end of the day as 23:59:59 from a date that is parsed using moment.js
var date = moment("2020-01-01").endOf("day").toDate();
Upvotes: 2
Views: 2198
Reputation: 11156
Ciao try to call .utc
in moment
like:
var date = moment("2020-01-01").utc().endOf("day").toDate();
Upvotes: 2
Reputation: 48600
I would keep the date as a moment object, up until you need to display it. Just simply call format
on the object.
console.log(moment.utc('2020-01-01').endOf('day').format('YYYY-MM-DDTHH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
Upvotes: 0