phpinfo()查看date模块是否支持,默认时区可能是UTC或者Europe/Berlin
设定一个脚本中所有日期时间函数的默认时区
bool date_default_timezone_set(string $timezone_id)
参数时区标识符,国内可以使用 "Asia/Shanghai"
date.timezone = PRC
取得脚本中所有日期时间函数所使用的默认时区
string date( string $format [, int $timestamp] )
- <?php
- echo date("Y年m月d日");
- echo date("y-n-j H:i:s");
- echo date("y-n-j G:i:s");
- echo date("y-n-j a h:i:s");
- echo date("y/n/j A g:i:s");
- echo date("t");
- echo date("w");
- echo date("L");
- ?>
- <?php
- echo "当前时间为:".date("Y-m-d H:i:s A")."<br>";
- echo "一天之后的时间为:".date("Y-m-d H:i:s A", time()+24*60*60)."<br>";
- echo "一周之后的时间为:".date("Y-m-d H:i:s A", time()+7*24*60*60)."<br>";
- echo "30天之后的时间为:".date("Y-m-d H:i:s A", time()+30*24*60*60)."<br>";
- ?>
int mktime([int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1] ] ] ] ] ] ])
参数从右到左可以省略,省略的参数会被设置为本地日期时间的当前值
- <?php
- // 2000年7月1日
- echo date("l", mktime(0,0,0,7,1,2016));
- // 2006年4月5日
- echo date("c", mktime(1,2,3,4,5,2016));
- ?>
int strtotime(string $time [, int $now = time() ] )
正确的日期时间格式:
Time Formats
Date Formats
Compound Formats
Relative Formats :
now +1 year +2 months +3 weeks +4 hours +5 minutes +6 days
yesterday today noon last day of next month 2 days ago
monday next week thursday
以上就是[PHP函数]日期时间函数的详细内容,更多关于[PHP函数]日期时间函数的资料请关注九品源码其它相关文章!