电脑时间钟代码(电脑时钟编程)

电脑时间钟代码(电脑时钟编程)function nbsp time year month day hour min s nbsp nbsp days 0 天数 nbsp nbsp days year 365 年化天 nbsp nbsp days month 1 30 1 月 月化天 nbsp nbsp days day 天化天 nbsp nbsp the year year 1 记录年数 作备用 进行闰年计算 nbsp nbsp 判断当前年是否计入计算 nbsp nbsp if month gt 2 month 2 amp amp days 29



function time(year,month,day,hour,min,s){

    days=0//天数

    days+=year*365//年化天

    days+=(month-1)*30//1月,月化天

    days+=day//天化天

    the_year=year-1//记录年数,作备用,进行闰年计算

    //判断当前年是否计入计算

    if(month>2||(month==2&&days==29)){

        the_year+=1

    }

    //闰年判定

    for(year_for=0;year_for<the_year+1;year_for++){

        if(year_for%400==0||(year_for%4==0&&year_for%100!=0)){

            days+=1

        }

    }

    //月31日判定

    if(month==12||month==11){

        days+=6

    }else if(month==10||month==9){

        days+=5

    }else if(month==8){

        days+=4

    }else if(month==7||month==6){

        days+=3

    }else if(month==5||month==4){

        days+=2

    }else if(month==3||month==2){

        days+=1

    }

    //2月判定

    if(month>2){

        days-=2

    }

    return ((days*24+hour)*60+min)*60+s

}

function time2(num){

    hour=Math.floor(num/3600)

    min=Math.floor(num%3600/60)

    s=num-hour*3600-min*60

    return {hour:hour,min:min,s:s}

}

编程小号
上一篇 2025-08-13 07:27
下一篇 2026-01-14 23:33

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/31737.html