Javascript – JS-Monatswechsel, bitte geben Sie mir Ideen oder Code
黄舟
黄舟 2017-06-30 09:56:38
0
1
766

// 时间切换
private tabTime(num: number) {
    let self = this;

    let now = new Date();
    let arr = [];

    if (num > 0) {
        this.num2 ++;
    }
    if (num < 0) {
        this.num2 --;
    }

    let b = Number(now.getMonth());

    now.setMonth(b + Number(this.num2)); // 输出时间

    let newA = now.getFullYear();
    let newB: any = Number(now.getMonth());
    let newC: any = now.getDay();
    newB = ((newB + 1) < 10 ? "0" : "") + (newB + 1);
    let y = newA + ' - ' + (newB);
    this.currMonthData = y;

    let days = this.getEveryMonthDays(newA, newB);

    this.StartTimeStamp = Number(newA + newB + "01");
    this.CurrTimeStamp = Number(newA + newB + days);

    this.loadChart(this.StartTimeStamp, this.CurrTimeStamp);

}
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

Antworte allen(1)
淡淡烟草味

如果month代表当前月份,通过 new Date(year, month-1) 获取上/下一个月,new Date(year, month, 0)获取上个月的最后一天,new Date(year, month, 1)获取当前月的第一天,new Date(year, month+1, 0)获取当前月的最后一天(也就是当前月的总天数)。然后通过这些值来计算切换后的月份天数和第一个星期前面的缩进天数,最后渲染出来

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage