date_default_timezone_get() — 取得一个脚本中所有日期时间函数所使用的默认时区

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了date_default_timezone_get() — 取得一个脚本中所有日期时间函数所使用的默认时区相关的知识,希望对你有一定的参考价值。

语法:

string date_default_timezone_get ( void )

本函数返回默认时区,使用如下“假定”的顺序:

  • 用 date_default_timezone_set() 函数设定的时区(如果设定了的话)

  • 仅仅php 5.4.0 之前: TZ 环境变量(如果非空)

  • date.timezone 配置选项(如果设定了的话)

  • 仅仅在 PHP 5.4.0 之前: 查询操作系统主机 (如果操作系统支持并允许)。 This uses an algorithm that has toguess the timezone. This is by no means going to work correctly for every situation. A warning is shown when this stage is reached. Do not rely on it to be guessed correctly, and set date.timezone to the correct timezone instead.

  • 如果以上选择都不成功,date_default_timezone_get() 会则返回 UTC 的默认时区

返回值

返回一个 string

范例

Example #1 获取默认时区

<?php
date_default_timezone_set(‘Europe/London‘);

if (date_default_timezone_get()) {
    echo ‘date_default_timezone_set: ‘ . date_default_timezone_get() . ‘<br />‘;
}

if (ini_get(‘date.timezone‘)) {
    echo ‘date.timezone: ‘ . ini_get(‘date.timezone‘);
}

?>

以上例程的输出类似于:

date_default_timezone_set: Europe/London
date.timezone: Europe/London

 

以上是关于date_default_timezone_get() — 取得一个脚本中所有日期时间函数所使用的默认时区的主要内容,如果未能解决你的问题,请参考以下文章

php 如何 获取 数字 时区,比如+8 -8

php如何获取服务器所在的时区?

ECShop安装实录

安装医用挂号系统,登录时出现这个情况怎么办

从 PHP 时区值生成 iCalendar VTIMEZONE 组件

php 中的 time() 函数表示当前时间是 1970