zoukankan      html  css  js  c++  java
  • 构建 分钟 构建天 构建 月份

    构建分钟  相隔5分钟

    function buildMinutes(){
    var a=[];
    for(var x=0;x<24;x++){
    if(x<10){
    x="0"+x
    }
    x=x+""
    a.push(x)
    }

    var b=[]
    for(var i=0;i<12;i++){
    var n=i;
    var m=n*5
    if(m<10){
    m="0"+m
    }
    b.push(m+"");
    }
    var minute=[]
    for(var j=0;j<a.length;j++){
    for(var k=0;k<b.length;k++){
    minute.push(a[j]+b[k]);
    }
    }
    return minute
    }
    console.log(buildMinutes())



    //构建天
    function buildDay (num) {
        num = num - 1;
    var myDate = new Date(this.pubTime); //获取今天日期
    myDate.setDate(myDate.getDate() - num);
    var dateArray = [];
    var dateTemp;
    var flag = 1;
    for (var i = 0; i < num; i++) {
    var month = myDate.getMonth() + 1
    if (month < 10) {
    month = "0" + month;
    }
    var day = myDate.getDate()
    if (day < 10) {
    day = "0" + day;
    }
    dateTemp = myDate.getFullYear() + "" + month + "" + day;
    dateArray.push(dateTemp);
    myDate.setDate(myDate.getDate() + flag);
    }
    dateArray.push(this.pubTime.replace(/-/g, ""))
    return dateArray
    }



    //构建月份
    function buildMonth(months) {
        var now = new Date(this.pubTime);
    var cur_month = now.getMonth();
    now.setDate(1);//重置成1号,原因:在做减月份时,减去的月份没有31号,会自动加1到下个月份,导致计算失误
    if (months < 0) {
    var _m = cur_month + months + 1;
    now.setMonth(_m);
    }
    var _months = [];
    for (var i = 0; i < Math.abs(months); i++) {
    var year = now.getFullYear();
    var month = now.getMonth();
    if (i != 0) {
    now.setMonth(month + 1);
    }
    year = now.getFullYear();
    var _month = now.getMonth() + 1;
    if (_month < 10) _month = '0' + _month;
    else _month = _month.toString();
    _months.push(year + _month);
    }
    return _months;
    }
     
  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/8508697.html
Copyright © 2011-2022 走看看