Change mat-datepicker selected date value according to a time zone

Discussão em 'Angular' iniciado por R0b1n, Agosto 5, 2025.

  1. R0b1n

    R0b1n Guest

    In ts. I have used a (dateChange)="setToDate($event.value)" to get selected date.

    <mat-form-field appearance="outline">
    <input matInput [matDatepicker]="picker2" readonly = "readonly" [(ngModel)] = "grid.todate"
    (dateChange)="setToDate($event.value)" [min]="grid.fromdate">
    <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
    <mat-datepicker #picker2></mat-datepicker>
    </mat-form-field>


    I want to change that selected date to the server time zone witch is in GMT.

    I have tried DatePip.

    public setToDate(data: any): void {
    const todayDate = new Date();
    this.todate = data._d;
    const changedDate = new DatePipe('en-Us').transform(data.toDate(), 'full', 'GMT');
    }


    The date picker picked the date at 00.00 am. Date pip will not give the time in GMT.

    Here's a the example > https://stackblitz.com/edit/material-date-picker-csyldt?embed=1&file=app/app.component.ts

    Continue reading...

Compartilhe esta Página