Alex Caron
Alex Caron

Reputation: 350

Angular - Date pipe

I'm trying to show a date correctly on IE in Angular. It's working fine in Chrome, Firefox, etc., but not on IE. This is my code :

<span>{{menu.modifiedDate ? (menu.modifiedDate | date : "dd-MM-y HH:mm:ss") : '-'}}</span>

This is what Google Chrome is showing :

15-06-2017 08:39:39

And this is what IE is showing :

15-06-2017 08:00:6/15/2017 8:39:39 AM:6/15/2017 8:39:39 AM 

What's wrong ?

Upvotes: 2

Views: 1725

Answers (2)

amin89
amin89

Reputation: 437

It's a common issue on IE. The best solution is to create your own pipe like this:

import { Pipe, PipeTransform } from '@angular/core';

    @pipe({
    name: 'date'
    })

    export class DataPipe implements PipeTransform {
    transform(value: string): string {

        let dd = value.substr(8, 2);
        let MM = value.substr(5, 2);
        let yyyy = value.substr(0, 4);
        let date = `${dd}/${MM}/${yyyy}`;

        return `${date}`;
    }
    }`

With this it should solve your problem.

Upvotes: 1

Oscar
Oscar

Reputation: 66

That is an old issue https://github.com/angular/angular.js/issues/13880

You might be working with an old version. Upgrading to the latest stable version should fix the problem.

Upvotes: 2

Related Questions