在 Ionic Angular 中需要 Day Week Month Year 的日期功能
Need Date functionality for Day Week Month Year in Ionic Angular
我想在 Angular 中显示当前的日期、周、月和年单击小于符号时的一天和前一天我需要显示周、月和年。
看起来 ion-datetime 就是您要找的。
if (this.tabID === "Day") {
const nextDay = new Date(myDate1);
nextDay.setDate(myDate1.getDate() + 1);
this.currentDate = nextDay;
console.log("next ", nextDay);
}
if (this.tabID === "Month") {
// for month
const nextMonth = new Date(myDate1);
nextMonth.setMonth(myDate1.getMonth() + 1);
console.log("month ", nextMonth);
this.currentDate = nextMonth;
}
if (this.tabID === "Week") {
// for next week
const firstDay = new Date(this.currentDate);
const nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
console.log("next week> ", nextWeek);
this.currentDate = nextWeek;
const current = new Date(this.currentDate); // get current date
const weekstart = current.getDate(); // - 1 - current.getDay() + 1;
const weekend = weekstart - 6; // end day is the first day + 6
this.weekStart = new Date(current.setDate(weekstart)); // first day of week is Sunday
this.weekEnd = new Date(current.setDate(weekend)); // last day of week is Saturday
console.log("weekStart ", this.weekStart, "WeekEnd ", this.weekEnd);
}
if (this.tabID === "Year") {
const nextMonth = new Date(myDate1);
nextMonth.setFullYear(myDate1.getUTCFullYear() + 1);
console.log("month ", nextMonth);
this.currentDate = nextMonth;
}
}```
by doing this I resolved the issue.
this code is for only greater than icon in image
我想在 Angular 中显示当前的日期、周、月和年单击小于符号时的一天和前一天我需要显示周、月和年。
看起来 ion-datetime 就是您要找的。
if (this.tabID === "Day") {
const nextDay = new Date(myDate1);
nextDay.setDate(myDate1.getDate() + 1);
this.currentDate = nextDay;
console.log("next ", nextDay);
}
if (this.tabID === "Month") {
// for month
const nextMonth = new Date(myDate1);
nextMonth.setMonth(myDate1.getMonth() + 1);
console.log("month ", nextMonth);
this.currentDate = nextMonth;
}
if (this.tabID === "Week") {
// for next week
const firstDay = new Date(this.currentDate);
const nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
console.log("next week> ", nextWeek);
this.currentDate = nextWeek;
const current = new Date(this.currentDate); // get current date
const weekstart = current.getDate(); // - 1 - current.getDay() + 1;
const weekend = weekstart - 6; // end day is the first day + 6
this.weekStart = new Date(current.setDate(weekstart)); // first day of week is Sunday
this.weekEnd = new Date(current.setDate(weekend)); // last day of week is Saturday
console.log("weekStart ", this.weekStart, "WeekEnd ", this.weekEnd);
}
if (this.tabID === "Year") {
const nextMonth = new Date(myDate1);
nextMonth.setFullYear(myDate1.getUTCFullYear() + 1);
console.log("month ", nextMonth);
this.currentDate = nextMonth;
}
}```
by doing this I resolved the issue.
this code is for only greater than icon in image