I've tried to display date in mat-datepicker (angular-material) in UTC time using:
{provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS,
useValue: {useUtc: true}
but it won't work.
How may I do that?
I've tried to display date in mat-datepicker (angular-material) in UTC time using:
{provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS,
useValue: {useUtc: true}
but it won't work.
How may I do that?
Hi I had this problem too and have found an answer elsewhere so seems a good idea to add it here.
import {
MAT_MOMENT_DATE_FORMATS, MomentDateAdapter,
MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';
import {
DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import * as moment from 'moment';
providers: [
{provide: MAT_DATE_LOCALE, useValue: 'en-GB'}, // optional but gets my dates in dd/mm/yy format
{provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: {useUtc: true}},
{
provide: DateAdapter,
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS]
},
{provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},
],
and then dont use : Date types, use : moment.Moment types.
That should clear it up but you can also use moment.utc() to really double down on it.