1//how to use
2//example: {{ yourDate | date:'short'}}
3
4'short': equivalent to 'M/d/yy, h:mm a' (6/15/15, 9:03 AM).
5'medium': equivalent to 'MMM d, y, h:mm:ss a' (Jun 15, 2015, 9:03:01 AM).
6'long': equivalent to 'MMMM d, y, h:mm:ss a z' (June 15, 2015 at 9:03:01 AM GMT+1).
7'full': equivalent to 'EEEE, MMMM d, y, h:mm:ss a zzzz' (Monday, June 15, 2015 at 9:03:01 AM GMT+01:00).
8'shortDate': equivalent to 'M/d/yy' (6/15/15).
9'mediumDate': equivalent to 'MMM d, y' (Jun 15, 2015).
10'longDate': equivalent to 'MMMM d, y' (June 15, 2015).
11'fullDate': equivalent to 'EEEE, MMMM d, y' (Monday, June 15, 2015).
12'shortTime': equivalent to 'h:mm a' (9:03 AM).
13'mediumTime': equivalent to 'h:mm:ss a' (9:03:01 AM).
14'longTime': equivalent to 'h:mm:ss a z' (9:03:01 AM GMT+1).
15'fullTime': equivalent to 'h:mm:ss a zzzz' (9:03:01 AM GMT+01:00).
1'short': equivalent to 'M/d/yy, h:mm a' (6/15/15, 9:03 AM).
2'medium': equivalent to 'MMM d, y, h:mm:ss a' (Jun 15, 2015, 9:03:01 AM).
3'long': equivalent to 'MMMM d, y, h:mm:ss a z' (June 15, 2015 at 9:03:01 AM GMT+1).
4'full': equivalent to 'EEEE, MMMM d, y, h:mm:ss a zzzz' (Monday, June 15, 2015 at 9:03:01 AM GMT+01:00).
5'shortDate': equivalent to 'M/d/yy' (6/15/15).
6'mediumDate': equivalent to 'MMM d, y' (Jun 15, 2015).
7'longDate': equivalent to 'MMMM d, y' (June 15, 2015).
8'fullDate': equivalent to 'EEEE, MMMM d, y' (Monday, June 15, 2015).
9'shortTime': equivalent to 'h:mm a' (9:03 AM).
10'mediumTime': equivalent to 'h:mm:ss a' (9:03:01 AM).
11'longTime': equivalent to 'h:mm:ss a z' (9:03:01 AM GMT+1).
12'fullTime': equivalent to 'h:mm:ss a zzzz' (9:03:01 AM GMT+01:00).
1// In Angular
2// Html
3<p>{{myDate | date: 'dd-MM-yyyy'}}</p>
4// Typescript
5myDate: Date = new Date();
1//how to use
2//example: {{ yourDate | data:'short'}}
3
4'short': equivalent to 'M/d/yy, h:mm a' (6/15/15, 9:03 AM).
5'medium': equivalent to 'MMM d, y, h:mm:ss a' (Jun 15, 2015, 9:03:01 AM).
6'long': equivalent to 'MMMM d, y, h:mm:ss a z' (June 15, 2015 at 9:03:01 AM GMT+1).
7'full': equivalent to 'EEEE, MMMM d, y, h:mm:ss a zzzz' (Monday, June 15, 2015 at 9:03:01 AM GMT+01:00).
8'shortDate': equivalent to 'M/d/yy' (6/15/15).
9'mediumDate': equivalent to 'MMM d, y' (Jun 15, 2015).
10'longDate': equivalent to 'MMMM d, y' (June 15, 2015).
11'fullDate': equivalent to 'EEEE, MMMM d, y' (Monday, June 15, 2015).
12'shortTime': equivalent to 'h:mm a' (9:03 AM).
13'mediumTime': equivalent to 'h:mm:ss a' (9:03:01 AM).
14'longTime': equivalent to 'h:mm:ss a z' (9:03:01 AM GMT+1).
15'fullTime': equivalent to 'h:mm:ss a zzzz' (9:03:01 AM GMT+01:00).
1
2 content_copy
3
4 @Component({
5 selector: 'date-pipe',
6 template: `<div>
7 <p>Today is {{today | date}}</p>
8 <p>Or if you prefer, {{today | date:'fullDate'}}</p>
9 <p>The time is {{today | date:'h:mm a z'}}</p>
10 </div>`
11})
12// Get the current date and time as a date-time value.
13export class DatePipeComponent {
14 today: number = Date.now();
15}
16
1import { Pipe, PipeTransform } from '@angular/core';@Pipe({ name: 'dateCount'})export class DateCountPipe implements PipeTransform { transform(value: any): number { let today:Date = new Date(); //get current date and time let todayWithNoTime:any = new Date(today.getFullYear(), today.getMonth(), today.getDate()) var dateDifference = Math.abs(value - todayWithNoTime) //returns value in miliseconds const secondsInDay = 86400; //60 seconds * 60 minutes in an hour * 24 hours in a day var dateDifferenceSeconds = dateDifference*0.001; //converts miliseconds to seconds var dateCounter = dateDifferenceSeconds/secondsInDay; if (dateCounter >= 1 && value > todayWithNoTime){ return dateCounter; }else{ return 0; } }}