[英]How can I format date in Angular and TypeScript?
我有一個顯示日期的表格。
我的表格同時顯示日期和時間,但我只想顯示日期。
這是我的代碼:
import {DatePipe, formatDate} from '@angular/common';
import * as moment from 'moment/moment';
export class RegistrationModel{
firstName: string;
lastName: string;
middleName: string;
nickname: string;
createdAt: string;
applicantCV: string;
mobileNumber: string;
emailAddress: string;
datePipe = new DatePipe('en-US');
constructor(response){
//formatDate(this.createdAt, 'M/d/yy', 'en-US');
this.firstName = response.firstName;
this.lastName = response.lastName;
this.middleName = response.middleName;
this.nickname = response.personalData.nickname;
this.createdAt = response.createdAt;
this.datePipe.transform(this.createdAt, 'M/d/yy');
this.applicantCV = response.applicantCV;
this.mobileNumber = response.contactInfo.mobileNumber;
this.emailAddress = response.contactInfo.emailAddress;
}
}
我猜您在轉換日期后忘記重新分配createdAt
變量。
this.createdAt = this.datePipe.transform(new Date(this.createdAt), 'M/d/yy');
編輯
您似乎還必須先將 createdAt 轉換為 Date。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.