I think I know why already.
ngx-bootstrap
datepicker cannot support moment
object binding to ngModel
, that why using ._d
to make it Date
object.
<input class="form-control m-input" type="datetime" bsDatepicker [(ngModel)]="date._d" id="Date" name="Date">
Since I enabled UTC mode, ._d
object carry the UTC date and convert again to UTC datetime to the backend, that I always cannot get the correct UTC datetime. End up when displaying in the label, it always shows one day before the exact date. So, remove ._d
, create a Date
object and use toDate()
to convert moment
object to Date
obejct will solve the issue for Result 2.
I found that there is ._d
in the input which messed up the utc datetime.
I am using ASP.Net Core Angular version 7.0.0.
Scenario: When I select a date with datepicker (29/10/2019) in the UI, I get one day before the date (28/10/2019) in the backend, and stored the date (28/10/2019) in database.
Solutions: Use Clock.Now; for date Set Clock.Provider = ClockProviders.Utc; in Startup.cs Set Timezone (UTC+8) in Host and Tenant Setting page
Results:
Questions: