Giter VIP home page Giter VIP logo

Comments (11)

rweng avatar rweng commented on August 14, 2024 16

For the NgxMatNativeDateModule:

const INTL_DATE_INPUT_FORMAT = {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hourCycle: 'h23',
  hour: '2-digit',
  minute: '2-digit',
};

const MAT_DATE_FORMATS: NgxMatDateFormats = {
  parse: {
    dateInput: INTL_DATE_INPUT_FORMAT,
  },
  display: {
    dateInput: INTL_DATE_INPUT_FORMAT,
    monthYearLabel: { year: 'numeric', month: 'short' },
    dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
    monthYearA11yLabel: { year: 'numeric', month: 'long' },
  },
};

// providers: [{ provide: NGX_MAT_DATE_FORMATS, useValue: MAT_DATE_FORMATS }],

from angular-material-components.

vitaliidasaev avatar vitaliidasaev commented on August 14, 2024 4

Fixed with this code:

import {
  // modules
  NgxMatDatetimePickerModule,
  NgxMatDateFormats,
  NGX_MAT_DATE_FORMATS,
} from '@angular-material-components/datetime-picker';
import {NgxMatMomentModule, NGX_MAT_MOMENT_DATE_ADAPTER_OPTIONS} from '@angular-material-components/moment-adapter';

export const MOMENT_DATETIME_WITH_SECONDS_FORMAT = 'YYYY-MM-DD HH:mm:ss';

// If using Moment
const CUSTOM_MOMENT_FORMATS: NgxMatDateFormats = {
  parse: {
    dateInput: MOMENT_DATETIME_WITH_SECONDS_FORMAT,
  },
  display: {
    dateInput: MOMENT_DATETIME_WITH_SECONDS_FORMAT,
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

@NgModule({
  declarations: [],
  imports: [
    MatDatepickerModule,
    MatMomentDateModule,
    NgxMatMomentModule,
    NgxMatDatetimePickerModule,
  ],
  exports: [
    MatDatepickerModule,
    MatMomentDateModule,
    NgxMatMomentModule,
    NgxMatDatetimePickerModule,
  ],
  entryComponents: [ConfirmationDialogComponent],
  providers: [
    // values
    {provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: {useUtc: true}},
    {provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_MOMENT_FORMATS},
    {provide: NGX_MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: {useUtc: true}},
  ],
})
export class SharedModule {}

from angular-material-components.

jeremylcarter avatar jeremylcarter commented on August 14, 2024 2

from angular-material-components.

jeremylcarter avatar jeremylcarter commented on August 14, 2024

Is it possible to change the formatting to show AM / PM?

from angular-material-components.

vitaliidasaev avatar vitaliidasaev commented on August 14, 2024

from angular-material-components.

h2qutc avatar h2qutc commented on August 14, 2024

@jeremylcarter You can also customize the date format by providing your custom NGX_MAT_DATE_FORMATS in your module.

// If using Moment
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
  parse: {
    dateInput: "l, LTS"
  },
  display: {
    dateInput: "l, LTS",
    monthYearLabel: "MMM YYYY",
    dateA11yLabel: "LL",
    monthYearA11yLabel: "MMMM YYYY"
  }
};

//and in the module providers 
providers: [
    { provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_MOMENT_FORMATS }
  ]

from angular-material-components.

yatashashank avatar yatashashank commented on August 14, 2024

I am facing the same issue. Is this issue fixed ??

from angular-material-components.

abrasat avatar abrasat commented on August 14, 2024

@rweng @jeremylcarter How can the above solution (display 00 instead of 24 for the hours in ngx-mat-datetime-picker) be adapted/extended to have also a customized format of the date, for example as "17.01.2022" instead of the default "1/17/2022". I am looking for a solution without using the moment library.

from angular-material-components.

sbrogliato avatar sbrogliato commented on August 14, 2024

@abrasat I have the same problem, have you solved it?

from angular-material-components.

abrasat avatar abrasat commented on August 14, 2024

@sbrogliato see solution here

from angular-material-components.

mpods2022 avatar mpods2022 commented on August 14, 2024

@rweng
I reviewed the code and implemented.
image
I want to customize the format like below.
2022/12/05 13:43
Can you help me?

from angular-material-components.

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.