如何更改 angular 中 smart table 任意列的日期格式?
how to change date format in moment of any column of smart table in angular?
这是我的自定义 pipe,我用它来更改 moment 中的日期。
eg:1 个月前
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'createdDate' })
export class MomentPipe implements PipeTransform {
transform(createdDate:Date) {
const m=moment("createdDate").fromNow()
return m;
}
}
此 object 用于显示 table 标题栏。
settings = {`enter code here`
createdDate: {
title: 'Date Created',
valuePrepareFunction: (createdDate) => {
if (createdDate) {
return new MomentPipe().transform(createdDate , 'M/d/yyyy');
}
return null;
}, } } };
更改管道代码:
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'createdDate' })
export class MomentPipe implements PipeTransform {
transform(createdDate:Date) {
const m=moment(createdDate).fromNow()
return m;
}
}
这是我的自定义 pipe,我用它来更改 moment 中的日期。 eg:1 个月前
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'createdDate' })
export class MomentPipe implements PipeTransform {
transform(createdDate:Date) {
const m=moment("createdDate").fromNow()
return m;
}
}
此 object 用于显示 table 标题栏。
settings = {`enter code here`
createdDate: {
title: 'Date Created',
valuePrepareFunction: (createdDate) => {
if (createdDate) {
return new MomentPipe().transform(createdDate , 'M/d/yyyy');
}
return null;
}, } } };
更改管道代码:
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'createdDate' })
export class MomentPipe implements PipeTransform {
transform(createdDate:Date) {
const m=moment(createdDate).fromNow()
return m;
}
}