有谁知道是否可以禁用日期/时间选择器自动将 UTC 时间添加到日期对象?如下图所示,它会自动将我的日期对象调整为 UTC。我希望我的日期对象在 10:00:00 提交
{"reportedDate": "2019-02-13T15:00:16.000Z"}
<p-calendar required [(ngModel)]="entry.reportedDate" name="reportedDate" #reportedDate="ngModel" [showIcon]="true" [showTime]="true" dateFormat="mm/dd/y 'EST'" hourFormat="24"></p-calendar>
最佳答案
根据 the documentation page for this component (在属性表中):
Name Type Default Description ----------------------------------------------------------------------------- dataType string date Type of the value to write back to ngModel, default is date and alternative is string.
你应该通过
[dataType]="string"
。这将阻止构建 Date
对象,从而阻止任何时区转换。另外,我建议不要在条目的格式中放置时区缩写。请记住,夏令时可能会生效,具体取决于所选日期,而且并非每个时区都有清晰一致的缩写,并且某些缩写(例如 CST 或 IST)不明确。
如果您需要向用户表明该条目是美国东部时间,请将其放在文本框之外的某个位置。如果必须使用缩写,请使用
ET
作为通用形式。
关于angular - PrimeNG 日历 <p-calendar> - 如何禁用 UTC - Z 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54752165/