获取网站's设置时间范围的时间

Getting website's time to set time range

本文关键字:时间 设置 范围 网站 获取      更新时间:2023-09-26

有没有办法获得网站的当前时间来设置反应的范围时间?

例如如果CCD_ 1&amp;website < 15:00 当前时间

do reaction
else
another reaction

我想每30秒做一次这种检查类型的功能

编辑

例如,如果在我的国家,时间是14:00,而在另一个国家是19:00,我想根据我国家的时间对另一个国做出反应。如果我做错了,请纠正我的错误。

这里是php文件获取服务器时间的代码,将其命名为t.php.

<?php
$b = time (); 
echo date("H",$b);
?>

下面是您使用ajax的其他文件的代码:使用example/wamp运行此文件。将两个文件都放在sane目录中。

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript"> 
setInterval(function() {
    $.ajax({
        url : "t.php",
        type: 'GET',        
        success: function(data){            
            if(data >= 9 && data < 10){ 
                alert('yes');
              // do something
            } else{ 
                alert('no');
                 // do something
            }
        }
    });
}, 1000);
</script>

以下是解决方案:您可以使用javascript查找网站的当前时间,因为它是客户端脚本语言

在php中,我认为无法找到客户端的时间(不确定),这就是我使用jquery的原因。要在php文件中使用它,请使用ajax。

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
function call_notification_count() {
        var todaydate = new Date(); // current time of browser. or you can say Time of client's location
        var month = todaydate.getMonth()+1+"";if(month.length==1)  month="0" +month;
        var date = todaydate.getDate()+"";if(date.length==1) date="0" +date;
        var year = todaydate.getFullYear();
        var hours = todaydate.getHours();
        var minutes = todaydate.getMinutes();
        var seconds = todaydate.getSeconds();
        var todaytime = hours+":"+minutes+":"+seconds;
        var todaydateonly = year+"-"+month+"-"+date+" ";        
        alert(todaytime);
        if(hours >= 14){
                // do something
        }else{
                // do something
        }
    }
    setInterval(call_notification_count, 3000); // Set time intervel here like for every 30 sec.
});
</script>