question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support UTC mode for datepicker

See original GitHub issue

Bug, feature request, or proposal:

feature request

What is the expected behavior?

having docs and examples

What is the current behavior?

not having docs and examples

What are the steps to reproduce?

look here : https://github.com/angular/material2/blob/master/src/lib/datepicker/datepicker.md and here : https://material.angular.io/components/datepicker/api

fail to find out how to implement a mat datepicker input that doesn’t localize dates.

What is the use-case or motivation for changing an existing behavior?

my end-user wishes to save universal dates to his ERP and have those be loaded into this client without localization as this would mess with the shipment calculations.

NOTE : end-user DOES however wish for internationalized currency and date formats. So I do have global internationalization set up in my modules but within my specific form component I wish to stop the datepicker’s current behavior of messing with the date that the user picks : right now with FR i18n, when I pick image

then hit “send” my Typsescript function is set to grab the datepickers value and send it to the JAVA backend.

In my chrome code inspector, I can see that the API call has : 2018-11-24T23:00:00.000Z

that’s one day earlier. how do I end this once and for all?

I tried this in the component :

import { MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';

@Component({
  selector: 'app-details',
  templateUrl: './details.component.html',
  styleUrls: ['./details.component.scss'],
  animations: [slideLeftAnimation],
  providers: [
    { provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
  ]
})
export class DetailsComponent implements AfterContentInit, OnDestroy {

  @ViewChild(MatDatepicker) datepicker: MatDatepicker<Date>;

but that did nothing, then I tried this :

import { MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';
import { MatDatepicker } from '@angular/material';

@Component({
  selector: 'app-details',
  templateUrl: './details.component.html',
  styleUrls: ['./details.component.scss'],
  animations: [slideLeftAnimation],
  providers: [
    { provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
  ]
})
export class DetailsComponent implements AfterContentInit, OnDestroy {

  @ViewChild(MatDatepicker) datepicker: MatDatepicker<Date>;

but I got this : image (“can’t assign date to matDatePicker”, basically)

So I deduced a setter function of some sort must have been implemented, not being auto-suggested any by my IDE, I decided to head on over to the datepicker documentation which feature no setter function.

I’m stuck.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
jelbourncommented, Oct 3, 2018

@mmalerba is there a way to make the datepicker always in UTC today?

2reactions
chipicowcommented, Mar 13, 2019

@mmalerba adding the providers in your stackblitz was a life savior thanks! to edit the date format to ‘dd/mm/yyyy’ I added to the providers {provide: MAT_DATE_LOCALE, useValue:‘en-GB’}

Read more comments on GitHub >

github_iconTop Results From Across the Web

UTC date for mat-datepicker in Angular 6 - Stack Overflow
I have created a sample on stackblitz. You can find out more at Choosing a date implementation and date format settings. Share. Share...
Read more >
How to make date input / date picker display the date as if it ...
I know that both UTC midnight date creation and date -> UTC string is possible with native javascript. Angular even has a native...
Read more >
Angular Mat Date Moment Utc - StackBlitz
Datepicker with date only utc moment.
Read more >
Options — bootstrap-datepicker documentation - Read the Docs
Options¶. All options that take a “Date” can handle a Date object; a String formatted according to the given format ; or a...
Read more >
Datepicker - Angular Material
Therefore, the datepicker input also has support for (dateInput) and ... You can change the default behaviour to parse dates as UTC by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found