Reputation: 949
I want to set the default value of datetime-local to current date and time(time should contain only Hours and minutes like '2014-01-02T11:42'.) using angularJs.
EDIT: following is my html code
<center><input type="datetime-local" name="start date" ng-model="endDate" id="from_date"></center>
angularJs code
$scope.endtDate=new Date(new Date().getTime()).toLocaleString();
by this method I am able to set the current date and time but it also inclodes seconds and milliseconds.
Upvotes: 2
Views: 3809
Reputation: 949
changed the code and solved my problem
$scope.endDateTime=new Date();
var h = $scope.endDateTime.getHours();
var m = $scope.endDateTime.getMinutes();
$scope.endDateTime.setHours(h,m,0,0);
this will only set hours and minutes. cheers :)
Upvotes: 1
Reputation: 649
Use angular filter put the date variable instead of the numbers.
<script>
var app = angular.module('myApp', []);
app.controller('dateCtrl', function($scope) {
$scope.today = new Date();
});
</script>
Plunker: https://plnkr.co/edit/HXDsILCtyliiamxdABZn?p=preview
<body ng-app="" ng-controller="dateCtrl">
<span>{{today | date:"MM/dd/yyyy'T' h:mm"}}</span><br>
</body>
Upvotes: 0
Reputation: 881
You should use date filter for displaying date..
Look at the following link..
http://www.w3schools.com/angular/tryit.asp?filename=try_ng_ref_date
https://docs.angularjs.org/api/ng/filter/date
I hope this will help
Upvotes: 0