Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
angular2 date pipe locale_id period

I have a problem with the angular2 date pipe when using danish locale.

When I format a date like:

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

it outputs the day of the date with a suffixed period like this:

17.-03-2017

allthough I would expect it to be like this:

17-03-2017

The locale is set in the app.module like this:

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

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

UPDATE

It probably has something to do with the way dates are formatted 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

Notice the dot

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

localization is "platform independent", ECMAscript provides specifications and each Javascript engine provides its own implementation.

There is also a compatibility implementation, Intl.js, which will provide the API if it doesn't already exist. You can see the implementation for the locale Danish (Denmark) here, you will see the available formats, and the day always returns the period after.

 "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",

You could create a custom pipe, and chain it to remove the period

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

@Pipe({name: 'removePeriod'})
    export class RemovePeriodPipe implements PipeTransform {
      transform(input: string) {
        return input.replace(/\./g, '');
      }
    }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!