Search code examples
angulardatetimepickeraspnetboilerplate

Angular DateTimePicker field in ABP


I have a DateTime field that is supposed to show only time:

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',
    });
}

It shows the value correctly when the page loads but every time I hit the save button a random time is set to the object to be sent to the server!The Date part is fine though!


Solution

  • Well, It was adding 10:30 hours to it because of my Time zone. The trick was in the back-end when comparing entered dates with today date and time I had to do it with the Clock.Now rather than DateTime.Now.