Angular date parsing unexpected output

2019-07-16 14:59发布

问题:

I'm trying to display a date using the date action, but it's giving odd output.

{{ mydate | date:'mm/dd/yyyy' }}

The month seems to be inconsistent and incorrect. What's wrong here?

回答1:

You need to use MM to display the month:

{{ mydate | date:'MM/dd/yyyy' }}

From the documentation

'MM': Month in year, padded (01-12)
...
'mm': Minute in hour, padded (00-59)


回答2:

You need to use date:'MM/dd/yyy'

mm is for minutes, MM is for months