Angular2 datePipe 返回格式化日期但还有一个月
Angular2 datePipe returning formatted date but with an additional month
这是我的格式化函数:
public formatDate(date: Date): string {
var datePipe = new DatePipe();
if (date) {
return datePipe.transform(date, 'yMd');
} else {
return "--";
}
};
我用的时候
let dateFooBar = new Date(2016, 5, 10); //NOtice month 5!!!!
console.log("Date : " + this.formatDate(dateFooBar)) //output: Date : 6/10/2016
Date
class 在 Angular 2 JavaScript[=24 中的正常行为=],看看这个:
export class HeroBirthdayComponent {
birthday = new Date(1988, 3, 15); // April 15, 1988
}
你可以查看我提供的官方文档和示例on Angular 2 official website。
您还可以在 w3schools 上查看 JavaScript Date
class 了解更多详情。
这是我的格式化函数:
public formatDate(date: Date): string {
var datePipe = new DatePipe();
if (date) {
return datePipe.transform(date, 'yMd');
} else {
return "--";
}
};
我用的时候
let dateFooBar = new Date(2016, 5, 10); //NOtice month 5!!!!
console.log("Date : " + this.formatDate(dateFooBar)) //output: Date : 6/10/2016
Date
class 在 Angular 2 JavaScript[=24 中的正常行为=],看看这个:
export class HeroBirthdayComponent {
birthday = new Date(1988, 3, 15); // April 15, 1988
}
你可以查看我提供的官方文档和示例on Angular 2 official website。
您还可以在 w3schools 上查看 JavaScript Date
class 了解更多详情。