Skip to content

Instantly share code, notes, and snippets.

@taknb2nch
Created June 15, 2019 07:43
Show Gist options
  • Save taknb2nch/646d427002def03dc3bae2450ef9f567 to your computer and use it in GitHub Desktop.
Save taknb2nch/646d427002def03dc3bae2450ef9f567 to your computer and use it in GitHub Desktop.
moment.jsを使った日付Pipeのサンプル実装
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'mydate'
})
export class MyDatePipe implements PipeTransform {
transform(value: any, format?: string) {
if (value === null || value === undefined) {
return '';
}
if (!format) {
format = 'YYYY/MM/DD';
}
const d = moment(value);
return d.isValid() ? d.format(format) : '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment