php入门时间,PHP入门(8)日期和时间
PHP語言默認的是格林威治時間,要獲取本地時間必須要修改PHP語言中的時區(qū)設(shè)置。
修改時區(qū)設(shè)置有兩種方式
修改配置文件php.ini
[Date]
date.timezone=Asia/Hong_Kong
2.在應(yīng)用程序中修改時區(qū)
date_default_timezone_set(timezone);
timezone可以設(shè)置為"PRC" "Asia/Chongqing" "Asia/Shanghai"
可以通過下面的代碼驗證
echo?date("Y-m-d?H:i:s");
Unix時間戳:自1970年1月1日起到當前時刻經(jīng)歷的秒數(shù)。
獲取當前的時間戳
int mktime()
echo?mktime();
echo?date("Y-m-d",mktime());//使用date函數(shù)格式化后的日期??年-月-日
echo?date("H:i:s",mktime());?//時:分:秒
還可以通過time()函數(shù)獲取當前的時間戳
int time(void)
//獲取下一周的日期
$nextweek?=?time()?+?7*24*60*60;
echo?"Next?week:".date("Y-m-d",$nextweek);
strtotime()可以將英文文本解析為Unix時間戳
int strtotime(string str);
echo?strtotime("now");
echo?strtotime("+3?day");//三天后的時間戳
echo?strtotime("+1?week");//一周后的時間戳
echo?strtotime("next?Thursday");
以數(shù)組的形式返回時間的信息
array getdate(int timestamp);
這些時間函數(shù)不用死記硬背,用的時候查就行。
總結(jié)
以上是生活随笔為你收集整理的php入门时间,PHP入门(8)日期和时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dedecms index_testen
- 下一篇: oracle数据库视图存放位置,orac