简体   繁体   中英

Simple PHP time date script

I am a PHP beginner and can't seem to get time script working

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)

if time is between 24 - 11.10, then message 1 and echo time

if time is between 11.10 - 24, message 2 and echo time

please help

script is targeted and should treat all users as coming from a specific timezone GMT+6 (Kyrgyzstan)

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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