Reputation: 87
Mat date range date picker displays the wrong value
I need the start value 2021-02-01T00:00:00.000Z
Upvotes: 0
Views: 535
Reputation: 1
I don't know, if it is still relevant for you.
I always use Luxon for formatting Dates: https://github.com/moment/luxon It does seem, like you didn't use that yet, given your stackblitz.
With that, you can add some providers for correct formatting:
{ provide: MAT_DATE_LOCALE, useValue: 'de' },
{
provide: DateAdapter,
useClass: LuxonDateAdapter,
deps: [MAT_DATE_LOCALE, MAT_LUXON_DATE_ADAPTER_OPTIONS],
},
{ provide: MAT_DATE_FORMATS, useValue: MAT_LUXON_DATE_FORMATS },
// if you want to work with utc-dates, you need to add this line
{ provide: MAT_LUXON_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } },
Hope that helps. :)
Upvotes: 0
Reputation: 31
By default datepicker works with your local time (probably your time is +5.30 ). Need to provide:
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true }},
If you want to work with UTC dates by default.
Upvotes: 1