1
votes

How to force Angular material's datepicker not to convert date to UTC? When I select a date, everything is okay, but when I get a date in my server side, it is the previous date.

<mat-form-field class="ship-calendar">
    <input matInput 
        [matDatepicker]="shipPickerInput 
        [(ngModel)]="rowData.ShipDate"
        disabled 
        (dateChange)="shipmentFocusout($event, rowData, 'ShipDate')">
    <mat-datepicker-toggle matSuffix [for]="shipPickerInput">
    </mat-datepicker-toggle>
    <mat-datepicker #shipPickerInput disabled="false">
    </mat-datepicker>
</mat-form-field>

I send this ShipDate to myserver.

1
Send timestamps, they will be handled as per your server locale - user4676340
how do you save/send your date? can you provide some code? - molamk
I have added my code sample. - Aspram
The easiest way would be to convert the time you send to the server as utc. I'm not sure what the format is on the server if it's only a date/time then you need to convert back from utc to current timezone in your app. If the format include the timezone on your server your app can most likely convert it on it's own. So what you get is timezone>UTC>timezone. - Swoox

1 Answers

1
votes

use this method. your.ts file

rowData={ ShipDate }

assign date to this variable :

date = new Date();

then assign:

this.rowData.ShipDate=this.date;

hope this will work for you. :)