Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. import { Pipe, PipeTransform } from '@angular/core';
  2. import * as moment from 'moment';
  3.  
  4. @Pipe({
  5. name: 'mydate'
  6. })
  7. export class MyDatePipe implements PipeTransform {
  8. transform(value: any, format?: string) {
  9. if (value === null || value === undefined) {
  10. return '';
  11. }
  12.  
  13. if (!format) {
  14. format = 'YYYY/MM/DD';
  15. }
  16.  
  17. const d = moment(value);
  18.  
  19. return d.isValid() ? d.format(format) : '';
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement