简体   繁体   English

Bootstrap Datepicker 取值比所选日期少一天

[英]Bootstrap Datepicker taking value as one-day less than the selected date

I am using Bootstrap date-picker for capturing a certain date.我正在使用 Bootstrap 日期选择器来捕获某个日期。 But the selected date will become one-day less when its passed to backend.但是当它传递到后端时,选定的日期将减少一天。 The date I slected in UI -> 04-Apr-1997 The date shown in console -> 1997-04-03T18:30:00.000Z (as you can see...one day behind)我在 UI 中选择的日期 -> 1997 年 4 月 4 日控制台中显示的日期 -> 1997-04-03T18:30:00.000Z (如您所见......落后一天)

HTML HTML

<div class="col-sm-9">
            <input id="OfficialDob" placeholder="Date of Birth" class="form-control" bsDatepicker [bsConfig]="bsConfig"
              formControlName="OfficialDob" />
          </div>

TYPESCRIPT TYPESCRIPT

this.bsConfig = Object.assign(
      {},
      {
        containerClass: this.datepickerColorTheme,
        zIndexOffset: -3,
        dateInputFormat: 'DD-MMM-YYYY',
        showWeekNumbers: false
      }
    );

Why is it like this?为什么会这样? Could anyone figure me how to do it?谁能告诉我该怎么做? Thanks谢谢

Its not an error.它不是错误。 Datepicker takes input and sets date considering the timezone. Datepicker 接受输入并考虑时区设置日期。 While in console, it show the date in ISO format.在控制台中,它以 ISO 格式显示日期。 Use date.toLocaleDateString() and you will see the date you set.使用 date.toLocaleDateString() 你会看到你设置的日期。 Or consider adding timezone offset to the date if required.或者,如果需要,可以考虑将时区偏移添加到日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM