Reputation: 11
let datetimeStamp = '2020-07-11T00:05:00';
let flightDateTime = new Date(datetimeStamp);
flightDateTime.getMonth()
// Output is 6
But it should be 7 as per datetimeStamp provided.
Upvotes: 1
Views: 35
Reputation: 4032
To format date directly in HTML , we can also use angular date pipe
{{datetimeStamp | date:'MMM dd,yyyy'}}
or
{{(datetimeStamp | date:'MMM dd,yyyy') || 'No Date Found'}}
Upvotes: 0
Reputation: 2453
getMonth()
returns values from 0
(for January) to 11
(for December), so you need to manually add +1
to adjust your value properly:
let month = flightDateTime.getMonth() + 1
For further details, have a look here: https://www.w3schools.com/jsref/jsref_getmonth.asp
Upvotes: 2