Locale DateTime in ABP



我在弹出模式中有一个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并按下"保存"按钮时,MomentJ确实将其转换为UTC时间并将其发送到服务器,并最终将其保存在DB中。我的问题是关于从服务器回到字段的数据时。我以为时刻。

任何输入都非常感谢:(

我最终将我的格式化方法更改为以下:

formatDate(date: any, format: string): string {
    return moment.utc(date.toString()).local().format(format);
}

它显示了从DB获取值的本地时间,但是现在问题是在更新其值时。当我保存表单时,它将日期视为当地时间,并且每次从中扣除10:30,然后发送到服务器!

这是场景:

  1. 假设这是DB中保存的UTC时间:2018-02-23 00:00:00
  2. 在填充该字段时,它添加了10:30(我的本地时区(,并在现场显示:2018-02-23 10:30:00
  3. 我在不更改上述值的情况下保存表单
  4. 瞬间从服务器(2018-02-23 00:00:00(扣除10:30小时的时刻,并将其发送给服务器以保存。
  5. 然后,我对该字段有一个新值,而没有以形式更改(2018-02- 22 13:30:00(!

最新更新