Comments (11)
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.
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.
from angular-material-components.
Is it possible to change the formatting to show AM / PM?
from angular-material-components.
from angular-material-components.
@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.
I am facing the same issue. Is this issue fixed ??
from angular-material-components.
@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.
@abrasat I have the same problem, have you solved it?
from angular-material-components.
@sbrogliato see solution here
from angular-material-components.
@rweng
I reviewed the code and implemented.
I want to customize the format like below.
2022/12/05 13:43
Can you help me?
from angular-material-components.
Related Issues (20)
- Cannot use datetime-picker with Angular 15 and Angular Material 14
- Angular 17 compatibility HOT 14
- [Angular 16] Angular 16.2.1. breaks the styling of the datetimepicker component HOT 2
- more than 2 datetime picker in one page which is load dynamically & Not able to change the format
- [Angular 10] Keyboard navigation broken
- About the ngx-matdate-time-picker
- Switching between the years is very slow on the date picker version 8 HOT 3
- Spinner icons are not loading HOT 2
- Optional HEX Color Input field
- want to have keyboard toggle in dates HOT 1
- ngx-mat-datetime-picker is improperly formatted in angular 16 HOT 3
- Datepicker design breaks Angular 13 HOT 2
- angular upgrade V16 to V17 HOT 1
- No option for language change
- No Arabic digits in the time field
- latest version is not supported with Angular 17. HOT 1
- latest version is not supported with Angular 17 HOT 2
- Time picker only
- Is there problems when i using 16.0.1 in angular V17 project HOT 2
- Angular v18 migration issue HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-material-components.