AngularJS. Convert tag value (Unix time to human-readable time)

前端 未结 6 1158
萌比男神i
萌比男神i 2020-12-01 03:37

I am getting data from a database and displaying it:

    
  • {{item.date}}
6条回答
  •  不知归路
    2020-12-01 03:54

    I have faced the issue with unix time formatted as a number of seconds from the epoch start or as a number of milliseconds that is used in JavaScript. So strictly speaking, AngularJS doesn't convert Unix timestamp to Date, but a number with milliseconds, which is 1000 times larger, so first you will have to multiply your input number by 1000, like this:

    {{item.date * 1000 | date:'yyyy-MM-dd HH:mm:ss Z'}}
    

    Otherwise your date will be wrong.

提交回复
热议问题