Angular2 pipe date locale_id period

I have a problem with angular2 date date when using Danish locale.

When I format the date, for example:

{{myDate | date:'dd-MM-yyyy'}} 

it displays the day of the date with a suffix like this:

17.-03-2017

allthough, I would expect it to be like this:

03/17/2017

The locale is set in app.module as follows:

providers: [ {provide: LOCALE_ID, useValue: 'da-DK'} ]  

I made this plnkr to make it more understandable http://plnkr.co/edit/A5ddrKP5cmsSZ9bTqzPh

UPDATE

This is likely due to the way dates are dated in Danish. Se below:

var locale = 'da-DK'; 
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; 
var date = new Date(2017,2,17); var result = new Intl.DateTimeFormat(locale, options).format(date); 
alert(result); 

turns into → fredag ​​den 17. marts 2017

Pay attention to the point

+6
source share
1 answer
Localization

" ", ECMAscript , Javascript .

, Intl.js, API, . () , , .

 "availableFormats": {
                "d": "d.",
                "E": "ccc",
                "Ed": "E 'den' d.",
                "Ehm": "E h.mm a",
                "EHm": "E HH.mm",
                "Ehms": "E h.mm.ss a",
                "EHms": "E HH.mm.ss",
                "Gy": "y G",
                "GyMMM": "MMM y G",
                "GyMMMd": "d. MMM y G",

,

{{myDate | date:'dd-MM-yyyy'|removePeriod}}

@Pipe({name: 'removePeriod'})
    export class RemovePeriodPipe implements PipeTransform {
      transform(input: string) {
        return input.replace(/\./g, '');
      }
    }
+2

Source: https://habr.com/ru/post/1015839/


All Articles