How can I get current date and time in angularjs
I have tried the following:
{{Date.Now}}
But it d
In your controller
scope.v.Dt = Date.now();
The DOM syntax is
{{v.Dt | date:'medium'}}
For an example -
Output -
Oct 28, 2010 8:40:23 PM
Define getDatetime method on scope
scope.getDatetime = function() {
return (new Date).toLocaleFormat("%A, %B %e, %Y");
};
Then in template:
<b>{{getDatetime()}}</b>
Doc to format date https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat
In Component file:
this.registerDate = new Date().toJSON("yyyy/MM/dd HH:mm");
this.updateDate = new Date().toJSON("yyyy/MM/dd HH:mm");
In Template file:
<span class="font-size-13px">{{registerDate}}</span>
<span class="font-size-13px">{{updateDate}}</span>
Result will return:
In your controller - scope.v.Dt = Date.now();
The DOM syntax is -
{{v.Dt | date:'medium'}}
For an example -
Output -
Oct 28, 2010 8:40:23 PM
For all possible date formats - http://docs.angularjs.org/api/ng.filter:date
Thanks all I got it by your all of answer
<b>{{getDatetime | date:'yyyy-MMM-dd'}}</b>
In controller,
$scope.getDatetime = new Date();