查看所有包含 时区 标签的文章
七月
26

[Hack]更改article模组输出feed时时间不对的缺陷

Author Dominic    Category XOOPS     Tags , , , ,

服务时区设置为+8,在命令行行下显示正常,中设置服务器所在时区为+0800,可输出的时时间却怎么也不对,导致outlookRSS订阅中显示的文章时间也不对均为GMT+1600时区,哪有这样的时区哦,时区范围GMT-1200~GMT+1200。

修改方法如下:

1、修改htdocs\modules\\class\feedcreator.class.php文件中739行附近FeedDate类的构造函数FeedDate如下:

   1: function FeedDate($dateString="") {
   2:     $tzOffset = 0;
   3:     if ($dateString=="") $dateString = date("r");
   4:  
   5:     //if (is_integer($dateString)) {
   6:     if (is_numeric($dateString)) {
   7:         $this->unix = $dateString;
   8:         return;
   9:     }
  10:    // By XuYong 调整日期格式
  11:     if (preg_match("~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~",$dateString,$matches)) {
  12:         $months = Array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);
  13:         $this->unix = gmmktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]);
  14:         if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {
  15:             $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
  16:         } else {
  17:             if (strlen($matches[7])==1) {
  18:                 $oneHour = 3600;
  19:                 $ord = ord($matches[7]);
  20:                 if ($ord < ord("M")) {
  21:                     $tzOffset = (ord("A") - $ord - 1) * $oneHour;
  22:                 } elseif ($ord >= ord("M") AND $matches[7]!="Z") {
  23:                     $tzOffset = ($ord - ord("M")) * $oneHour;
  24:                 } elseif ($matches[7]=="Z") {
  25:                     $tzOffset = 0;
  26:                 }
  27:             }
  28:             switch ($matches[7]) {
  29:                 case "UT":
  30:                 case "GMT":    $tzOffset = 0;
  31:             }
  32:         }
  33:
  34:         $tzOffset += date("Z",0);
  35:         $this->unix += $tzOffset;
  36:  
  37:         if (TIME_ZONE!="")
  38:         {
  39:             $server_TZ = abs(intval($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0));
  40:             $this->unix += ($server_TZ - date("Z", 0)) % 43200;
  41:         }
  42:  
  43:         return;
  44:     }
  45:     if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) {
  46:         $this->unix = gmmktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);
  47:         if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {
  48:             $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
  49:         } else {
  50:             if ($matches[7]=="Z") {
  51:                 $tzOffset = 0;
  52:             }
  53:         }
  54:         $tzOffset += date("Z",0);
  55:         $this->unix += $tzOffset;
  56:  
  57:         if (TIME_ZONE!="")
  58:         {
  59:             $server_TZ = abs(intval($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0));
  60:             $this->unix += ($server_TZ - date("Z", 0)) % 43200;
  61:         }
  62:         return;
  63:     }
  64:     $this->unix = 0;
  65: }

2、修改htdocs\modules\\class\xml.php文件58行,

原来为:

$TIME_ZONE = $prefix.date(“H:i”, $server_TZ);

修改为:

$TIME_ZONE = $prefix.date(“H:i”, ($server_TZ – date(“Z”, 0)) % 43200); // By XuYong 调整时区显示,防止出现+1600时区

四月
26

cnBeta订阅时区不对问题及linux下时区设置兼容性问题,慎用CST时区

cnBeta是我非常喜爱的IT资讯站,装上Outlook 2007之后就用Outlook来完成订阅工作了,但是郁闷的是他的订阅条目的时间老是比当前时间早一些,动不动时间就是明天的了。打开http://www.cnbeta.com/backend.php页面代码发现里面的时区完全不对,不符合RSS2.0规范,RSS标准时区表示方法是GMT+0800这种格式,而采用的是时区,很多unix下中国时区(Asia/Shanghai)都是用表示的。但是这个表示方法非常不合理,实际上表示以下四种时区:

Central Standard Time (USA) UTC-6:00 (美国)中部标准时间

Central Standard Time (Australia) UTC+10:30 中澳大利亚标准时间

China Standard Time UTC+8:00 中国沿海时间(北京时间)

Cuba Standard Time UTC-4:00 古巴标准时间

在unix下通过/etc/localtime这个硬连接指向的/usr/share/zoneinfo下的时区文件表示当前的真正时区。比如/etc/localtime指向了/usr/share/zoneinfo/Asia/Shanghai这个文件的时候,就代表了中国标准时间。但是很多语言的时间函数库根本不做这个判断,往往就是用一个独立的时区配置文件做时区关键字和GMT的转换。因此很多系统里面都变成了GMT-6,也就是美国中部时间。所以采用作为时区设置就会有兼容性的问题了。

在Windows中更是如此,所以订阅老是相差14个小时UTC-0600的现在不就是现在之后的14个小时吗。最根本的解决方法应该是改变unix服务器的时区,采用GMT+0800时区或者UTC+0800。

实际上中国标准时间(GMT+0800)的正确缩写是CCT,而不是

更改服务器时区方法是:在/usr/share/zoneinfo/目录下,找到期望的时区,拷贝覆盖/etc/localtime ,然后reboot即可得到新的时区

查询、修改时间方式: 
# hwclock命令 -r 查询BIOS时间 -w 内核时间写入BIOS 
# date命令 -s
更改时间或日期

完成修改时区的工作之后可以通过#ntpdate命令来根据NTP服务器更新本地时间。

的订阅也有时间问题,但我解决了,改天整理以下再发布。站长们检查一下网站订阅链接的时区是否正确吧。

专题推荐

标签

apache article CSS dotNet fckeditor Hack iOS iTouch javascript PayPal PHP rar ubuntu utf8 VMware VMware Tools weblinks Win2008 Windows Server 2008 Wordpress xajax XOOPS 上传 个人 中文 中文习惯 关键词 分享 合肥 域名 安全 工作 插件 文章管理 时区 未分类 模块 模板 模组 电子地图 界面友好 禅意花园 网速 腾讯 配置管理

分类目录

新浪微博

存档

最近文章

近期评论

友情链接

分享按钮