2015-09-15 60 views
0

我有時間輸入字段我正在獲取星期四01 1970年12月59日格林威治標準時間+ 0530(印度標準時間)像這樣我只想要時間。爲什麼我越來越像這樣是否有任何問題在時間選擇器在angularjs任何人幫助我?不合適日期格式在angularjs

function HistoryCtrl($scope) { 
 

 
    $scope.updateForm = function() { 
 
     console.log($scope.booktime); 
 
     //here i am getting Thu Jan 01 1970 12:59:00 GMT+0530 (India Standard Time) 
 
     
 
    }; 
 

 
    
 
}
<div ng-app ng-controller="HistoryCtrl"> 
 
    
 
    <div class="col"> 
 
      <label class="item item-input item-stacked-label"> 
 
      <span class="input-label" >Time</span> 
 
      <input type="time" ng-model="booktime" name="booktime" min="09:00:00" max="21:00:00" required=""> 
 
      </label> 
 
      <div class="form-error" ng-messages="projectForm.booktime.$error"> 
 
       <div class="form-error" ng-message="required">* Mandatory</div> 
 
       <div class="form-error" ng-message="min">Booking times: 9am - 9 pm</div> 
 
       <div class="form-error" ng-message="max">Booking times: 9am - 9 pm</div> 
 
      </div> 
 
     </div> 
 
    
 
    <button ng-click="updateForm()">Update</button> 
 
    
 
</div>

回答

0

Angularjs有$filter服務提供的日期格式。

爲了你的方便,我在下面提供的樣本:

function HistoryCtrl($scope, $filter) { 

    $scope.updateForm = function() { 
     console.log($filter('date')($scope.booktime, 'mediumTime'));   
    }; 
} 

你可以通過this鏈接有時間你想要的格式。

希望這將有助於:)

+0

我得到錯誤錯誤:[$注射器:unpr]未知提供商:11點32分00秒amFilterProvider < - 11點32分00秒amFilter HTTP://errors.angularjs .org/1.3.13/$ injector/unpr?p0 = 11%3A32%3A00%20amFilterProvider%20%3C-%2011%3A32%3A00%20amFilter at REGEX_STRING_REGEXP(angular.js:63) –

+0

如何通過$ scope.booktime = data.Scheduled_Time; –

+0

再次我需要將此值傳遞給時間輸入不提取 –

0

您可以使用手柄日期時間moment.js。

http://momentjs.com/

或者使用

https://github.com/urish/angular-moment爲angularjs

格式的日期

moment().format('MMMM Do YYYY, h:mm:ss a'); // September 15th 2015, 10:30:07 am 
moment().format('dddd');     // Tuesday 
moment().format("MMM Do YY");    // Sep 15th 15 
moment().format('YYYY [escaped] YYYY');  // 2015 escaped 2015 
moment().format();       // 2015-09-15T10:30:07+05:30 
Relative Time 
moment("20111031", "YYYYMMDD").fromNow(); // 4 years ago 
moment("20120620", "YYYYMMDD").fromNow(); // 3 years ago 
moment().startOf('day').fromNow();  // 11 hours ago 
moment().endOf('day').fromNow();   // in 13 hours 
moment().startOf('hour').fromNow();  // 30 minutes ago 
Calendar Time 
moment().subtract(10, 'days').calendar(); // 09/05/2015 
moment().subtract(6, 'days').calendar(); // Last Wednesday at 10:30 AM 
moment().subtract(3, 'days').calendar(); // Last Saturday at 10:30 AM 
moment().subtract(1, 'days').calendar(); // Yesterday at 10:30 AM 
moment().calendar();      // Today at 10:30 AM 
moment().add(1, 'days').calendar();  // Tomorrow at 10:30 AM 
moment().add(3, 'days').calendar();  // Friday at 10:30 AM 
moment().add(10, 'days').calendar();  // 09/25/2015 
Multiple Locale Support 
moment().format('L'); // 09/15/2015 
moment().format('l'); // 9/15/2015 
moment().format('LL'); // September 15, 2015 
moment().format('ll'); // Sep 15, 2015 
moment().format('LLL'); // September 15, 2015 10:30 AM 
moment().format('lll'); // Sep 15, 2015 10:30 AM 
moment().format('LLLL'); // Tuesday, September 15, 2015 10:30 AM 
moment().format('llll'); // Tue, Sep 15, 2015 10:30 AM