Ability to customize the default format for DatePipe
See original GitHub issueWhich @angular/* package(s) are relevant/releated to the feature request?
common
Description
Currently the DatePipe
defaults the format to mediumDate
. It would be great if we could provide an InjectionToken
to customize it, like we already do for timezone
and locale
.
Proposed solution
Like the DATE_PIPE_DEFAULT_TIMEZONE
, we could have something like DATE_PIPE_DEFAULT_FORMAT
, so we can avoid to pass the most common format used in app (in my case shortDate
) for every | date
or even create our own pipe to override the default one.
Alternatives considered
Create our own pipe, but I’d prefer to avoid this… imagine if every app has its own DatePipe
? Also that sounds a bit weird to have InjectionToken
for timezone
and locale
, but not for the format.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:31
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Override Angular default date pipe - Stack Overflow
To override an angular pipe throughout the app, it's enough to add your custom pipe to the declarations array of your root AppModule:...
Read more >DatePipe - Angular
Field type Format Description
Era G, GG & GGG Abbreviated
GGGG Wide
GGGGG Narrow
Read more >Angular Tips: Formatting Dates with a Custom Date Pipe (dd ...
Using Angular default Date Pipe The date pipe accepts a format (optional parameter) that can be customized as showed in the code above...
Read more >Managing date formats in Angular apps | by Wojciech Trawiński
As a result, dates are rendered with the default format, unless you override it. Conclusions. Wrapping the built-in DatePipe into a custom one ......
Read more >Displaying Custom Date Formats in Angular 12 - HTML Goodies
The Angular DatePipe boasts 12 predefined formats, including “short“, “medium“, and “long“. These formats include both the date and time.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @flash-me, thanks for your input. As you may have noticed in the OP (Alternatives considered), we’re aware of the option of creating our own pipe, but the feature request is to include the
InjectionToken
in the Framework to be paired with the other parameters: timezone and locale.It sounds a bit strange to ask for every app to create their own
@Pipe
, instead of providing a token, like we’re already have for the other parameters.Given that we can use an injection token to customize the global timezone, this implementation should not be hard!