【发布时间】:2018-02-22 08:13:07
【问题描述】:
我在弹出模式中有一个 DateTime 字段,如下所示,它应该只显示时间部分:
HTML:
<div class='input-group date'>
<input class="form-control" type="datetime" #RequiredByDate name="RequiredByDate" [value]="formatDate(hitchRequest.requiredByDate, 'LT')" required>
<span class="input-group-addon">
<span class="fa fa-clock-o"></span>
</span>
</div>
TS:
formatDate(date: any, format: string): string {
if (!date) {
return '';
}
return moment(date).format(format);
}
onShown(): void {
$(this.requiredByDate.nativeElement).datetimepicker({
locale: abp.localization.currentLanguage.name,
format: 'LT',
});
}
当我设置 DateTime 并点击保存按钮时,momentjs 真正将其转换为 UTC 时间并将其发送到服务器,并最终以 UTC 时间保存在数据库中。 我的问题是关于何时将数据从服务器读回现场。我假设 moment.js 会将其重新转换回本地时区,就像它在设置其值时所做的那样,但事实并非如此!
任何意见都非常感谢:)
【问题讨论】:
-
如果你不想接受别人的答案或者你已经有了答案,为什么还要问问题?
-
@vivek-nuna 好吧,情况并非总是如此!我为这个问题提出的答案实际上不是答案!我这样放在那里,因为我的问题的更多细节不知道我可以编辑我的原始问题并添加更多内容! :) 您的回答部分解决了我的问题,但我仍在处理 UTC 时间从服务器发送回客户端。我也在这方面提出了一个问题here
标签: angular momentjs datetimepicker aspnetboilerplate