1 Star 0 Fork 0

JqueryObjects/ServerTime

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

从服务器获取时间并自动加1生成对应的时间

    $.ajax({
        url:"/systemSet/readDateTimeSet.do",
        type:"post",
        data:{},
        dataType:"json",
        success:function(data){
            var serverTime = data.nowTime.split(" ")[1],
                hours = serverTime.split(":")[0]-0,
                minutes = serverTime.split(":")[1]-0,
                seconds = serverTime.split(":")[2]-0;
            $("#hours").html(( hours < 10 ? "0":"" )+hours);
            $("#min").html(( minutes < 10 ? "0":"" )+minutes);
            $("#sec").html(( seconds < 10 ? "0":"" )+seconds);
            setInterval( function(){
                seconds += 1;
                if(seconds>59){
                    seconds = 0;
                    minutes +=1;
                    if(minutes>59){
                        minutes = 0;
                        hours +=1;
                        if(hours>23){
                            hours = 0;
                        }
                    }
                }
                $("#hours").html(( hours < 10 ? "0":"" )+hours);
                $("#min").html(( minutes < 10 ? "0":"" )+minutes);
                $("#sec").html(( seconds < 10 ? "0":"" )+seconds);
            },1000);
        }
    });

若不需求从服务器获取:

    var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
    var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
    // Create a newDate() object
    var newDate = new Date();
    
    // Extract the current date from Date object
    newDate.setDate(newDate.getDate());
    
    // Output the day, date, month and year
    $('#date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
    
    setInterval( function() {
    
        // Create a newDate() object and extract the seconds of the current time on the visitor's
        var seconds = new Date().getSeconds();
    
        // Add a leading zero to seconds value
        $("#sec").html(( seconds < 10 ? "0":"" ) + seconds);
    },1000);

    setInterval( function() {
    
        // Create a newDate() object and extract the minutes of the current time on the visitor's
        var minutes = new Date().getMinutes();
    
        // Add a leading zero to the minutes value
        $("#min").html(( minutes < 10 ? "0":"" ) + minutes);
    },1000);
    
    setInterval( function() {
    
        // Create a newDate() object and extract the hours of the current time on the visitor's
        var hours = new Date().getHours();
    
        // Add a leading zero to the hours value
        $("#hours").html(( hours < 10 ? "0" : "" ) + hours);
    }, 1000);

空文件

简介

从服务器获取时间并自动加1生成对应的时间 展开 收起
取消

发行版

暂无发行版

贡献者 (1)

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/JqueryObjects/ServerTime.git
git@gitee.com:JqueryObjects/ServerTime.git
JqueryObjects
ServerTime
ServerTime
master

搜索帮助