Evo_x Evo_x - 6 months ago 35
AngularJS Question

Angularjs - display current date

I got a view in angularjs and I'm just trying to display the current date(formatted). I thought something like

<span>{{Date.now() | date:'yyyy-MM-dd'}}</span>
should display the current date.

Answer

You have to create a date object in your controller first:

controller:

function Ctrl($scope)
{
    $scope.date = new Date();
}

view:

<div ng-app ng-controller="Ctrl">
    {{date | date:'yyyy-MM-dd'}}
</div>

JSFiddle example

Angular Date Filter Ref