获取我的页面开始的时间 运行 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;
   });