How to get Current Date time

前端 未结 5 693
日久生厌
日久生厌 2021-01-11 13:06

How can I get current date and time in angularjs

I have tried the following:

{{Date.Now}}

But it d

相关标签:
5条回答
  • 2021-01-11 13:25

    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

    0 讨论(0)
  • 2021-01-11 13:33

    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

    0 讨论(0)
  • 2021-01-11 13:34

    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:

    0 讨论(0)
  • 2021-01-11 13:37

    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

    0 讨论(0)
  • 2021-01-11 13:44

    Thanks all I got it by your all of answer

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

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

    0 讨论(0)
提交回复
热议问题