Skip to content
Advertisement

how to pass the manual time into the input type=”time” in js

I know you are fedup with these kind of repeated questions but still now i didn’t find answer for my question so please help me to solve this.. Thanks in advance.

html is :

var start="10:30 PM";
$scope.edit={}

frtime=start.split("PM")[0];
               frtime = frtime.trim();
               frtime= $filter('date')(frtime, "HH:mm");
               
               $scope.edit.fromtime=new Date("2010-12-28T"+frtime+":00");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<input type="time" ng-model="edit.fromtime">

It is showing some time in the input type field in html. But i need the 10.30 PM in the input field.

Advertisement

Answer

The JS Date object has methods for setting the hours, minutes, etc:

var newDate = new Date();
newDate.setHours(10,30,0)

Just create a new date, then set it to whatever value you need to:

Plunker

All the methods are here.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement