BSDATEPICKER。与TimePicker,如何删除AM/PM
我使用Angular 12和NGX-Bootstrap 7.1.2 当将datepicker与TimePicker一起使用时,如何格式化钟表? 在这种情况下,我想从中删除AM/PM,并允许用户以24小时格式选择时间。
这是我正在使用的代码,
<div class="text">
<input id="dpReview"
name="dpReview"
type="text"
required
#allocationDatepicker
class="form-control"
bsDatepicker
placeholder="Select an assignment date"
[(ngModel)]="allocDate"
[bsConfig]="{withTimepicker: true, dateInputFormat: 'MMMM DD YYYY, HH:mm'}"/>
</div>
谢谢
Im using angular 12 and ngx-bootstrap 7.1.2
When using the datepicker with timepicker, how can i format the timepicker?
In this case i want to remove the AM/PM from it and allow the user to select the time in the 24h format.
This is the code I'm using
<div class="text">
<input id="dpReview"
name="dpReview"
type="text"
required
#allocationDatepicker
class="form-control"
bsDatepicker
placeholder="Select an assignment date"
[(ngModel)]="allocDate"
[bsConfig]="{withTimepicker: true, dateInputFormat: 'MMMM DD YYYY, HH:mm'}"/>
</div>
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了这个问题,显然,datePicker不支持配置在内部集成的钟贴,即使TimePicker本身实际上确实支持它(甚至具有
@input
)。我将Angular 15与
。
我能够通过某种技巧解决问题来解决我的问题。让我清楚地说,这不是推荐的解决方案,因为它取决于datepicker和timepicker的某些内部功能。如果内部变更(例如私有属性或方法名称),解决方法将停止工作,或者(虽然不可能)可以在datepicker或timepicker中引入故障。
我本人仅使用它来暂时解决这个问题,但最终我将用自定义实施替换datepicker。
DatePicker具有事件发射器
开头
,可用于执行一些初始化。就我而言,它正在访问其中的钟贴组件,并覆盖负责呈现时间的私人方法。如您所见,
Showmeridian
属性是负责渲染12h格式的属性,请参见 github上的timepicker代码。此骇客仅将其简要介绍为
false
,然后在渲染后再次返回到true
。请注意,我尝试在初始化时尝试设置timepicker.showmeridian = false
,但这导致了奇怪的行为,渲染方法被无休止地称为,有效地停止了页面的工作。虽然此示例有效,但我会长期阻止其使用情况,而建议您实现自己的datepicker(也许只是通过将bootstrap datepicker和timepicker组合起来)或完全使用其他库。
I encountered this issue too, apparently the datepicker doesn't support configuring the timepicker integrated within, even though the timepicker itself actually does support it (an even has an
@Input
for it).I use Angular 15 with
[email protected]
.I was able to resolve my issue with a sort of hack-ish workaround. Let me be clear, this is not a recommended solution as it depends on some internal functionality of both the datepicker and timepicker. If the internals change (e.g. private property or method names) the workaround will stop working or (while improbable) can introduce glitches in the datepicker or timepicker.
I only used it myself to temporarily work around the issue for now, but eventually I will replace the datepicker with a custom implementation.
The datepicker has an event emitter
onShown
, which can be used to perform some initialization. In my case it's accessing the timepicker component inside it and override a private method responsible for rendering the time.As you see, the
showMeridian
property is the one for responsible for rendering the 12h format, see timepicker code on github.This hack only briefly sets it to
false
and then back totrue
again after the rendering. Note that I tried to just settimepicker.showMeridian = false
upon initialization instead, but that resulted in strange behavior and the rendering method being called endlessly, effectivelly stopping the page from working.While this example works, I discourage its usage long-term and instead recommend either implementing your own datepicker (maybe just by combining the bootstrap datepicker and timepicker yourself) or using a different library altogether.