How to get Current Date time

How can I get current date and time in angularjs

I have tried the following:

<b>{{Date.Now}}</b>

But it doesn't work. Any suggestions would be appreciated.

Answers:

Answer

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

Answer

Thanks all I got it by your all of answer

<b>{{getDatetime | date:'yyyy-MMM-dd'}}</b>

In controller, $scope.getDatetime = new Date();

Answer

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

Answer

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

Answer

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: enter image description here

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.