php判斷上午還是下午的實現方法:首先設置中國時區;然后定義一個GetDateTime方法;然后通過if else語句判斷當前時間是上午還是下午;最后輸出判斷結果即可。
推薦:《PHP視頻教程》
根據當前時間判斷上午好、下午好
header("Content-type:text/html;charset=utf-8"); date_default_timezone_set('PRC'); //設置中國時區 echo str_replace(array('AM','PM'),array('上午','下午'),date("Y-m-d A H:i:s"));
function GetDateTime(){ $Datetime = date('H'); $text = ""; if($Datetime >= 0 && $Datetime < 7){ $text = "天還沒亮,夜貓子,要注意身體哦! "; }else if($Datetime>=7 && $Datetime<12){ $text = "上午好!今天天氣真不錯……哈哈哈,不去玩嗎?"; }else if($Datetime >= 12 && $Datetime < 14){ $text = "中午好!午休時間哦,朋友一定是不習慣午睡的吧?!"; }else if($Datetime >= 14 && $Datetime < 18){ $text = "下午茶的時間到了,休息一下吧! "; }else if($Datetime >= 18 && $Datetime < 22){ $text = "下午茶的時間到了,休息一下吧! "; }else if($Datetime >= 22 && $Datetime < 24){ $text = "很晚了哦,注意休息呀!"; } return $text; }
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com