![](/img/trans.png)
[英]How to do total 24 hrs validation maintaning 12 hrs format using javascript?
[英]how to get 12 hrs format with AM/PM using angular?
$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); } }
我已經使用了角度和離子應用程序。在這里我遵循了這個gitup https://github.com/rajeshwarpatlolla/ionic-timepicker作為時間選擇器。當我選擇時間(例如我選擇了5pm)控制台時,我正在獲得價值61200這個或選定的時期是:61200,時間是17:0(在UTC中)我如何將其轉換為AM / PM格式的12hrs格式,任何人都可以幫助我
$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');
例如:
var yourDateObject = new Date();
var amPmHour = $filter('date')(yourDateObject, 'hh');
不要忘記為此調用$ filter模塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.