Every line of 'angular date pipe example' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
16 transform(value: string) { 17 let timeBefore; 18 const date = new Date(value); 19 timeBefore = 20 ('0' + date.getUTCFullYear()).slice(-2) + 21 '/' + 22 ('0' + (date.getUTCMonth() + 1)).slice(-2) + 23 '/' + 24 ('0' + date.getUTCDate()).slice(-2); 25 return timeBefore; 26 }
233 constructor( 234 private datePipe: DatePipe 235 ) { }
9 transform(value: Date | string | number, ...args: any[]): any { 10 if (!value) return ''; 11 return distanceInWords(value, new Date()) + ' ago'; 12 }
159 constructor(locale) { 160 this.locale = locale; 161 }
9 transform(inputDate: string): string { 10 const current = new Date().valueOf(); 11 const input = new Date(inputDate).valueOf(); 12 const msPerMinute = 60 * 1000; 13 const msPerHour = msPerMinute * 60; 14 const msPerDay = msPerHour * 24; 15 const msPerMonth = msPerDay * 30; 16 const msPerYear = msPerDay * 365; 17 18 const elapsed = current - input; 19 20 if (elapsed < msPerMinute) { 21 return Math.floor(elapsed / 1000) + 's'; 22 } else if (elapsed < msPerHour) { 23 return Math.floor(elapsed / msPerMinute) + 'm'; 24 } else if (elapsed < msPerDay) { 25 return Math.floor(elapsed / msPerHour) + 'h'; 26 } else if (elapsed < msPerYear) { 27 return Math.floor(elapsed / msPerDay) + 'd'; 28 } else { 29 return Math.floor(elapsed / msPerYear) + 'y'; 30 } 31 32 }
8 constructor(protected language: LanguageService) { 9 super(null); 10 }
44 public transform(value: DateTime | undefined | null, fallback = ''): string { 45 if (!value) { 46 return fallback; 47 } 48 49 return value.toStringFormat('dd. LLL yyyy'); 50 }
13 transform(query: string, ...args: any[]): any { 14 return query; 15 }
8 transform(value: any): string { 9 if (!value) { 10 return ''; 11 } else if (typeof value === 'string') { 12 value = parseISO(value); 13 } else { 14 value = new Date(value); 15 } 16 if (isValid(value)) { 17 return formatDistance(value, new Date(), { addSuffix: true }); 18 } else { 19 return ''; 20 } 21 }
79 private formatToDateString(date: Date, format: string): string { 80 return this.datePipe.transform(date, format); 81 }