Issue
How can I get the format, as a string, used by Angular to display dates ? I use the date
pipe after setting LOCALE_ID
in my app.module
.
Now I'd like to retrieve the "dd/mm/yyyy" string, to put in my input placeholders.
Basically, what's described here but for Angular.
Thanks
[edit]
To make it more explicit, I'm not looking for a way to format dates, that's already done (with the native date
pipe). I want the string that represents the format being used by this pipe.
Because I'd like my datepicker placeholder to be like
"Date (format: XXXXXX)"
and I want the "XXXXXX" part to be correct (i.e. "jj/mm/aaaa" for french, "mm/dd/yyyy" for english)
Solution
I hope that in the meantime you've come across getLocaleDateFormat() and getLocaleTimeFormat(). (Angular 6)
import { getLocaleDateFormat, FormatWidth } from '@angular/common';
export class Foobar {
constructor( @Inject( LOCALE_ID ) private locale: string ) { }
private getDateFormat() {
return getLocaleDateFormat( this.locale, FormatWidth.Short );
}
}
Answered By - Simon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.