如何在angularjs-datepicker中获得hh:mm:ss
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在angularjs-datepicker中获得hh:mm:ss相关的知识,希望对你有一定的参考价值。
嗨我正在使用angularjs datepicker功能使用npm i angularjs-datepicker
工作正常,但我需要显示时间像(15-12-2017 05:14 PM)帮助如何格式化datepicker在这里我提到参考链接也我累了控制器它来了但是当我点击错误显示的日期选择日期。有任何指定格式有帮助或如何解决该问题
https://www.npmjs.com/package/angularjs-datepicker
<div class="hackyhack" datepicker datepicker-class="test-custom-class"
date-format="dd-MM-y" >
<input type="text" id="AddQuoteDate" name="QuoteDate" size="4"
ng-model="QuoteDate" placeholder="Enter Quote Date"
ng-change="QuoteDatechange(QuoteDate)"
class="form-control angular-datepicker-input"
required title="Enter Quote Date"/>
</div>
调节器
$scope.QuoteDatechange = function (Quotedate) {
var date = new Date();
var hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
var am_pm = date.getHours() >= 12 ? "PM" : "AM";
hours = hours < 10 ? "0" + hours : hours;
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
time = hours + ":" + minutes + ":" + seconds + " " + am_pm;
$scope.QuoteDate = Quotedate + " " + time;
}
答案
根据DOCs你必须使用AngularJs date format
选项:date-format =“”
类型:字符串
默认值:String(new Date())
说明:设置要使用的日期格式,请参阅列表here
<datepicker date-format="dd-MM-yyyy hh:mm a" selector="form-control">
<input type="text" ng-model="QuoteDate"/>
</datepicker>
另一答案
这对我有用。试试这个。希望它会对你有所帮助。
var currentdate = new Date();
var hours = currentdate.getHours();
var minutes = currentdate.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ampm;
$scope.QuoteDate = pad(currentdate.getDate()) + "/"
+ pad(currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " "
+ strTime;
function pad(s) { return (s < 10) ? '0' + s : s; }
<input type="text" id="AddQuoteDate" name="QuoteDate" size="4" ng-model="QuoteDate" placeholder="Enter Quote Date" class="form-control angular-datepicker-input" required title="Enter Quote Date"/>
$('#AddQuoteDate').datetimepicker({
minDate:new Date(),
format: 'DD/MM/YYYY hh:mma'
});
以上是关于如何在angularjs-datepicker中获得hh:mm:ss的主要内容,如果未能解决你的问题,请参考以下文章
C ++:我在一种方法中获得了一个迭代器,如何在另一种方法中通过迭代器修改原始列表?