Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在angular js中-如何在单击按钮时获取当前时间_Javascript_Angularjs_Time - Fatal编程技术网

Javascript 在angular js中-如何在单击按钮时获取当前时间

Javascript 在angular js中-如何在单击按钮时获取当前时间,javascript,angularjs,time,Javascript,Angularjs,Time,我有两个按钮,比如输入和输出,我需要显示当前时间。。单击任何按钮后,我需要发送当前时间和日期 <label>Today's Date : {{currentdate}}</label> <label>Current Time : {{currenttime}}</label> <button type="submit" class="btn" ng-disabled="disabledin" value="in" ng-

我有两个按钮,比如输入和输出,我需要显示当前时间。。单击任何按钮后,我需要发送当前时间和日期

 <label>Today's Date : {{currentdate}}</label>
  <label>Current Time :  {{currenttime}}</label>

  <button type="submit" class="btn" ng-disabled="disabledin"  value="in" ng-
  click="submitFun($event)">IN</button>
  <button type="button" class="btn" ng-disabled="disabledout" value="out" 
   ng-click="submitFun($event)">OUT</button>
今天的日期:{{currentdate}
当前时间:{{currenttime}}
在里面
出来

关于
var time=new Date()

$scope.submitFun($event){
    $scope.currentDate = new Date();
    $scope.currentTime = new Date().getTime();
}
您可以使用html中的筛选器更改日期格式:

<label>Today's Date : {{currentdate | date:'yyyy-MM-dd HH:mm:ss Z'}}</label>
今天的日期:{{currentdate}日期:'yyyy-MM-dd HH:MM:ss Z'}

阅读一些您正在寻找的类似内容:

angular.module(“myApp”,[])
.controller(“myCtrl”,函数($scope){
$scope.someFunction=function(){
$scope.date=新日期();
}
})

当前日期:{date | date:'dd/MM/yyyy'}
时间:{date | date:'HH:mm:ss'}
显示日期时间
(函数(){
功能检查时间(i){
返回值(i<10)?“0”+i:i;
}
函数startTime(){
var today=新日期(),
$scope.currentdate=今天;
h=检查时间(今天。getHours()),
m=检查时间(today.getMinutes()),
s=检查时间(今天。getSeconds());
$scope.currenttime=h+“:“+m+”:“+s;
t=设置超时(函数(){
开始时间()
}, 500);
}
开始时间();
})();

将时间和日期发送到何处?您是否尝试过此解决方案以获取当前日期和时间?我尝试过@warl0ckto后端@ananthh获取时间和日期。但仅刷新页面我获取了不同的时间。为什么要使用此$scope.currentDate=date.getDate()+“/”+date.getMonth()+“/”+date.getFullYear()..在哪里可以简单地使用html中的日期过滤器???是的,但是时间应该是动态的@Sa EChowdary@user123这里的时间是动态的。尝试单击按钮多次,间隔几秒钟。或者您想要动态时间格式?您的$scope.currentTime=new Date().getTime();将返回类似1492410436254的内容,这是用户无法理解的time@SaEChowdary现在是表演时间。如果开发人员想要查看日期,他/她可以使用过滤器。是的,但是OP询问了当前日期的数据和时间……所以我要问的是如何做到这一点,就像您对当前日期所做的那样。这不是一种角度的方式!角度的方式是日期过滤器!
(function () {
    function checkTime(i) {
        return (i < 10) ? "0" + i : i;
    }

    function startTime() {
        var today = new Date(),
        $scope.currentdate = today;
            h = checkTime(today.getHours()),
            m = checkTime(today.getMinutes()),
            s = checkTime(today.getSeconds());
        $scope.currenttime = h + ":" + m + ":" + s;
        t = setTimeout(function () {
            startTime()
        }, 500);
    }
    startTime();
})();