Ricky
Ricky

Reputation: 702

Format Date Time in Angular 2

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

Upvotes: 9

Views: 29816

Answers (4)

Yasemin çidem
Yasemin çidem

Reputation: 623

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

Upvotes: 6

StepUp
StepUp

Reputation: 38094

In addition, to use RFC time standard just write the following format dd.MM.yy HH:mm:

{{ yourDate | date:'dd.MM.yy HH:mm' }} 

Output will be: 15.11.2018 16:38

Upvotes: 0

Lukasz Wiktor
Lukasz Wiktor

Reputation: 20422

Use date pipe:

{{dte | date}}

You can choose a predefined format (e.g. shortDate):

{{dte | date:'mediumDate'}}

Or specify your custom format:

{{dte | date:'MM dd, yyyy'}}

Upvotes: 8

Akshay Rao
Akshay Rao

Reputation: 3544

just use the pipe filter with ur {{dte}}...

just use {{dte |date:'MM/dd/yyyy @ h:mma'}}

it will give u your desired output :)

Upvotes: 11

Related Questions