Angularjs - display current date

后端 未结 11 1184
醉酒成梦
醉酒成梦 2020-12-04 08:06

I got a view in angularjs and I\'m just trying to display the current date(formatted). I thought something like {{Date.now() | date:\'yyyy-MM-dd\'}}

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 08:49

    Another way of doing is: In Controller, create a variable to hold the current date as shown below:

    var eventsApp = angular.module("eventsApp", []);
    eventsApp.controller("EventController", function EventController($scope) 
    {
    
     $scope.myDate = Date.now();
    
    });
    

    In HTML view,

    
    
    
        
       
       
    
    
    
    {{myDate | date : 'yyyy-MM-dd'}}

提交回复
热议问题