`
cakin24
  • 浏览: 1318031 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

输出UTC时间和北京时间

    博客分类:
  • PHP
阅读更多

一 代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>时区设置</title>
<style type="text/css">
<!--
.STYLE1 {
	font-size: 12px;
	color: #663300;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="305" height="160" border="0" cellpadding="0" cellspacing="0" background="images/bg.gif">
  <tr>
    <td width="50" height="60">&nbsp;</td>
    <td width="202">&nbsp;</td>
    <td width="53">&nbsp;</td>
  </tr>
  <tr>
    <td height="55">&nbsp;</td>
    <td valign="top" class="STYLE1">
	  <?php 
date_default_timezone_set("Europe/Dublin");	  
echo "UTC时间:".date("Y-m-d H:i:s");		//显示默认的UTC时间
date_default_timezone_set("PRC");		//使用中华人民共和国的时区
echo "<br>";
echo "北京时间:".date("Y-m-d H:i:s");	//输出北京时间
echo "<br>";
echo "当前时区:".date_default_timezone_get();	//获取当前时区
?>
 </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="45">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

 

二 运行效果

 
三 date_default_timezone_set函数介绍
date_default_timezone_set() 设定用于所有日期时间函数的默认时区。 
Note: 
自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。 
除了用此函数,你还可以通过 INI 设置 date.timezone 来设置默认时区。 
参数 
timezone_identifier
时区标识符,例如 UTC 或 Europe/Lisbon。
返回值 
如果 timezone_identifier 参数无效则返回 FALSE,否则返回 TRUE。
  • 大小: 31.5 KB
1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics