Hossam Elsagheer Hossam Elsagheer - 19 days ago 5
AngularJS Question

Format time using angular js

I want to fill a select (dropdownlist) with hours from 00 to 23 using angular
in the format "13:00","08:00" , i tied the following code :

<option ng-repeat="n in [].constructor(24) track by $index" value="{{$index}}">{{$index | date:'HH:mm'}}</option>


but the result is "02:00" for all 24 item of the select

Answer

Using the same calculation in Tomek Sulkowski's answer but use UTC in the date format so the value is independent to the local time zone.

<option ng-repeat="n in [].constructor(24) track by $index" value="{{$index}}">
    {{$index * 3600000 | date:'HH:mm' : 'UTC'}}
</option>