Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Date Time in Angular 2

Tags:

angular

How to display date time in Angular2?

{{dte}}

It prints date 2014-10-10T11:42:28.000Z

While I need it to print like:

Oct 10, 2015

like image 220
Ricky Avatar asked Jul 21 '16 12:07

Ricky


People also ask

What is the format of date () in angular?

The date filter formats a date to a specified format. By default, the format is "MMM d, y" (Jan 5, 2016).

How do I change date format in DatePipe?

You have to pass the locale string as an argument to DatePipe. var ddMMyyyy = this. datePipe. transform(new Date(),"dd-MM-yyyy");


1 Answers

You can use moment.js as a third party.

amDateFormat pipe

import {DateFormatPipe} from 'angular2-moment';
    @Component({
      selector: 'app',
      pipes: [DateFormatPipe],
      template: `
        Last updated: <time>{{myDate | amDateFormat:'LL'}}</time>
      `
    })

Prints Last updated: January 24, 2016 

Documentation: https://github.com/urish/angular2-moment

like image 108
Yasemin çidem Avatar answered Oct 02 '22 18:10

Yasemin çidem