[英]I want to compare the inserted date with current time in laravel 5 project
[英]i want compare the date and time and want show the differnce time in angularjs
我想比较日期和时间并想在 angularjs 中显示不同的时间,我是 yyyy/MM/dd 格式的 gettig 日期,
除了您的问题由于缺乏自己的代码而通常不值得回答这一事实之外,这已在 SO 上多次回答。 下一次,您应该添加一些有关您的问题和您正在努力处理的代码的更多信息。
无论如何,我为您提供了一个简单的解决方案(由@Tni提供支持):
var myApp = angular.module('myApp', []); myApp.controller('MyCtrl', function($scope) { $scope.date1 = '2015/01/01'; $scope.date2 = '2015/12/31'; $scope.getDateDiff = function() { var date1 = new Date($scope.date1), date2 = new Date($scope.date2), timeDiff = Math.abs(date2.getTime() - date1.getTime()); $scope.dateDiff = 'Amount of days difference: ' + Math.ceil(timeDiff / (1000 * 3600 * 24)); } });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="MyCtrl"> Date 1: <input type="text" ng-model="date1"> <br /><br /> Date 2: <input type="text" ng-model="date2"> <br /><br /> <button ng-click="getDateDiff()">Get Date Diff!</button> <br /><br /> {{dateDiff}} </div>
请检查此链接,您将获得更好的解决方案
html:
<div ng-app ng-controller="Ctrl">
{{date | date:'dd-MM-yyyy hh:mm '}} <br>
</div>
js:
function Ctrl($scope)
{
$scope.date = new Date();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.