Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2015-05-11 13:02:53

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.

Questioner
user3145744
Viewed
0
tpie 2015-05-11 22:38:45

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.