Coder Social home page Coder Social logo

Comments (4)

JusuVh avatar JusuVh commented on May 21, 2024

Hi,
I don't think it's clearly indicated in the docs by you should use the MAT_DATETIME_FORMATS provider to specify the formats for parsing and display.
Add this to your app.module providers (specifically the dateInput in the parse object) :

    {
      provide: MAT_DATETIME_FORMATS,
      useValue: {
        parse: {
          dateInput: 'DD/MM/YYYY HH:mm',
          timeInput: 'HH:mm',
        },
        display: {
          dateInput: 'DD/MM/YYYY',
          datetimeInput: 'DD/MM/YYYY HH:mm',
          timeInput: 'HH:mm',
          monthYearLabel: 'MMM YYYY',
          dateA11yLabel: 'LL',
          monthYearA11yLabel: 'MMMM YYYY',
        },
      }
    }

Also, there should be a datetimeInput in the parse object, because if you use date and datetime types at the same time, there is confusion on the format.

from mat-datetimepicker.

michaelsivo avatar michaelsivo commented on May 21, 2024

I have added the MAT_DATETIME_FORMATS to my module and changed

private adapter: DateAdapter<NativeDateAdapter>

into

private adapter: DatetimeAdapter<NativeDatetimeAdapter>

Now the datetimepicker only display the date and not the time. I think it is related to your last sentence but i didn't understand what you meant by date and datetime confusion. Is it related to the js Date type?

from mat-datetimepicker.

kuhnroyal avatar kuhnroyal commented on May 21, 2024

Date(time) parsing with the native date implementation is not supported, this is a limitation of the native date and the INTL API .
See Material2 native-date-adapter.ts

If you want to display and parse a certain datetime format, you have to use the moment adapter and set the display.datetimeInput and parse.datetimeInput properties to the same format. This works exactly the same way as the dateInput property for the official material datepicker does.

See datetime-formats.ts

from mat-datetimepicker.

michaelsivo avatar michaelsivo commented on May 21, 2024

Ok thanks!

from mat-datetimepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.