suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Javascript – JS-Monatswechsel, bitte geben Sie mir Ideen oder Code

// 时间切换
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);

}
黄舟黄舟2726 Tage vor744

Antworte allen(1)Ich werde antworten

  • 淡淡烟草味

    淡淡烟草味2017-06-30 09:58:38

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

    Antwort
    0
  • StornierenAntwort