Reputation: 1844
I need to create current date with time (7 am) with UTC timezone, but when I'm trying to format it time changing to wrong value:
code:
var t_day = moment().utcOffset(0)
t_day.set({ hour: 7, minute: 0, second: 0, millisecond: 0 })
console.log(t_day.toISOString())
console.log(t_day.format('MMM DD, YYYY HH:MM'))
Output:
2020-10-28T07:00:00.000Z
Oct 28, 2020 07:10
From where this 10 minutes came and how to format date properly?
Upvotes: 1
Views: 178
Reputation: 28434
mm
would refer to minutes:
var t_day = moment().utcOffset(0)
t_day.set({ hour: 7, minute: 0, second: 0, millisecond: 0 })
console.log(t_day.toISOString())
console.log(t_day.format('MMM DD, YYYY HH:mm'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Upvotes: 1
Reputation: 575
MM
in the format reffers to the month,
what you're looking for is mm
console.log(t_day.format('MMM DD, YYYY HH:MM')) // MM reffers to the month
// the correct should be:
console.log(t_day.format('MMM DD, YYYY HH:mm'))
Upvotes: 0