如何使用角度来获得AM / PM的12小时格式?

时间:2015-11-28 10:37:07

标签: javascript angularjs ionic-framework



$scope.timePickerObject12Hour = {
      inputEpochTime: ((new Date()).getHours() * 60 * 60 + 3600),  //Optional
      step: 15,  //Optional
      format: 12,  //Optional
      //titleLabel: '12-hour Format',  //Optional
      closeLabel: 'Close',  //Optional
      setLabel: 'Set',  //Optional
      setButtonType: 'button-positive',  //Optional
      closeButtonType: 'button-stable',  //Optional
      callback: function (val) {    //Mandatory
        timePicker12Callback(val);
      }
    };

    

    function timePicker12Callback(val) {
      if (typeof (val) === 'undefined') {
		  
        console.log('Time not selected');
      } else {
		 
        $scope.timePickerObject12Hour.inputEpochTime = val;
		console.log(val);
        var selectedTime = new Date(val * 1000);
       
      }
	 
    }




我使用了角度和离子app.here我跟随这个gitup https://github.com/rajeshwarpatlolla/ionic-timepicker时间选择器。当我选择时间(例如我选择了下午5点)控制台我得到这样的价值61200或 选定的纪元是:61200,UTC时间是17:0如何将其转换为12小时格式的AM / PM格式任何一个帮助我

$scope.timePickerObject12Hour.inputEpochTime = val;
        console.log(val);
        var selectedTime = new Date(val * 1000);
        console.log('Selected epoch is : ', val, 'and the time is ', selectedTime.getUTCHours(), ':', selectedTime.getUTCMinutes(), 'in UTC');

1 个答案:

答案 0 :(得分:0)

例如:

var yourDateObject = new Date();
var amPmHour = $filter('date')(yourDateObject, 'hh');

请勿忘记为此调用 $ filter 模块。

来自Angularjs Date documentation