简体   繁体   English

简单的PHP时间日期脚本

[英]Simple PHP time date script

I am a PHP beginner and can't seem to get time script working 我是PHP初学者,似乎无法使时间脚本正常工作

I need a simple PHP script that checks the local time of the user and shows a message based on user's current time or global time GMT + 6 (Kyrgyzstan) 我需要一个简单的PHP脚本来检查用户的本地时间,并根据用户的当前时间或全球时间GMT + 6(吉尔吉斯斯坦)显示一条消息

if time is between 24 - 11.10, then message 1 and echo time 如果时间在24-11.10之间,则消息1和回显时间

if time is between 11.10 - 24, message 2 and echo time 如果时间在11.10-24,消息2和回显时间之间

please help 请帮忙

script is targeted and should treat all users as coming from a specific timezone GMT+6 (Kyrgyzstan) 脚本是针对性的,应将所有用户都视为来自特定时区GMT + 6(吉尔吉斯斯坦)

If you don't need users local time, it is possible to do sth like: 如果您不需要用户本地时间,则可以执行以下操作:

$message = '';
$now = new \DateTime('now', new \DateTimeZone('KGT'));
if(intval($now->format('G')) > 11) {
    $message = 'msg1';
} else if(intval($now->format('G')) == 11 && intval($now->format('i')) > 10) {
    $message = 'msg1';
} else {
    $message = 'msg2';
}
echo $message;

If you pass users time via javascript you don't know timezone.. it depends on what you need.. 如果您通过javascript传递用户时间,您将不知道时区。这取决于您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM