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
The date filter formats a date to a specified format. By default, the format is "MMM d, y" (Jan 5, 2016).
You have to pass the locale string as an argument to DatePipe. var ddMMyyyy = this. datePipe. transform(new Date(),"dd-MM-yyyy");
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With