试图从日期对象数组中得到插值的日期,但当我使用 day.getDay()
比如本月的第13天,它显示的是 3
monthsDays = []
ngOnInit() {
const getDaysInMonth = (month, year) => (new Array(31)).fill('').map((v, i) => new Date(year, month - 1, i + 1)).filter(v => v.getMonth() === month - 1)
this.monthsDays = getDaysInMonth(new Date().getMonth() + 1, new Date().getFullYear())
console.log(this.monthsDays[12])
}
<div class="calendar owl-carousel owl-theme">
<div *ngFor="let day of monthsDays" class="item">{{day.getDay()}}</div>
</div>
你需要使用 .getDate()
.getDay()
返回一周中的某一天。
获取日期。https:/developer.mozilla.orgen-USdocsWebJavaScriptReferenceGlobal_ObjectsDategetDate。
获取日。https:/developer.mozilla.orgen-USdocsWebJavaScriptReferenceGlobal_ObjectsDategetDay。