簡體   English   中英

試圖從角度材料DatePicker中獲取日,年和月

[英]Trying to just get the Day, Year and Month from angular material DatePicker

我試圖獲取mm/dd/yyyy ,我嘗試使用Date.getFullYear()和其他方法,但是在Angular中不起作用。

<form class="example-container" 
            #employeeForms="ngForm" 
            (submit)="submit(employeeForms)">
    <mat-form-field>
        <input matInput [matDatepicker]="picker" placeholder="Due Date" name="date" [(ngModel)]="date">
        <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
        <mat-datepicker #picker></mat-datepicker>
    </mat-form-field>
</form>

console.log(data.value.date) // Wed Oct 10 2018 00:00:00 GMT-0400 (Eastern Daylight Time)`

您可以使用Moment.js將日期格式設置為“ DD / MM / YYYY”格式

moment(data.value.date).format('DD/MM/YYYY')

而且我不知道為什么像使用ngModel'date'一樣使用data.value.date

moment(this.date).format('DD/MM/YYYY')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM