Format Date time in AngularJS

后端 未结 13 1777
Happy的楠姐
Happy的楠姐 2020-11-30 22:00

How do I properly display the date and time in AngularJS?

The output below shows both the input and the output, with and without the AngularJS date filter:



        
13条回答
  •  野性不改
    2020-11-30 22:34

    You can use momentjs to implement date-time filter in angularjs. For example:

    angular.module('myApp')
     .filter('formatDateTime', function ($filter) {
        return function (date, format) {
            if (date) {
                return moment(Number(date)).format(format || "DD/MM/YYYY h:mm A");
            }
            else
                return "";
        };
    });
    

    Where date is in time stamp format.

提交回复
热议问题