获取我的页面开始运行 angularjs 的时间


Get the time my page started running angularjs

我正在制作一个显示当前系统时间的应用程序,但我想获取我的页面开始运行的时间,以便我可以计算和显示我的页面启动和运行的时间。我正在使用angularjs,目前不知道如何获得它。我有这样的获取当前系统时间的代码

 Current time is:
      <span my-current-time="format1"></span>
      <span my-current-time="format"></span> :
      <span my-current-time="format3"></span> :
      <span my-current-time="format4"></span> 
      <span my-current-time="format5"></span>

使用此脚本

 $scope.format1 = 'M/d/yy  ';
      $scope.format = 'h';
      $scope.format3 = 'mm';
      $scope.format4 = 'ss';
      $scope.format5 = 'a';
      $scope.format2 = 'Z ';

还有这样的指令

.directive("myCurrentTime", function(dateFilter) {
            return function(scope, element, attrs) {
              var format;
                scope.$watch(attrs.myCurrentTime, function(value) {
                  format = value;
                  updateTime();
                });
              function updateTime() {
                var dt = dateFilter(new Date(), format );
                         element.text(dt);
                      }
                      function updateLater() {
                        setTimeout(function() {
                          updateTime(); // update DOM
                          updateLater(); // schedule another update
                        }, 1000);
                      }
                      updateLater();
                    }
                  });

我只想显示我的页面当前运行的总小时数

首先保存页面加载值... $scope.pageLoad = new Date()

,然后使用筛选器显示该值

    <p>running since : {{pageLoan | timespan}}</p>

并定义时间跨度筛选器

  angular.filter(timespan, function(time){
         var now = new Date();
         return (now - time) / 1000;
   });