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

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

I am getting data from a database and displaying it:

    
  • {{item.date}}
6条回答
  •  自闭症患者
    2020-12-01 04:06

     yourapp.filter('timestampToDate', function () {
        return function (timestamp) {
            var date = new Date(timestamp * 1000);
            var dateObject = date.getFullYear() +'/'+ ('0' + (date.getMonth() + 1)).slice(-2) +'/'+ ('0' + date.getDate()).slice(-2);
            return dateObject;
        };
    });
    

    Usage:
    {{timestamp | timestampToDate}}

提交回复
热议问题