日期加下時差的計算方法-

來源:互聯網
上載者:User
日期加上時差的計算方法--急!!!!!

date_default_timezone_set('Etc/GMT');
$now = mktime(date('H'),date('i'),date('s'),date('m'),date('d'),date('Y'))+$timezone*60*60*1000;
$site_date = date("g:i A(D)",$now);


其中timezone是時差。為何我這麼用,擷取時間不對啊。。

請高手幫忙解決。


------解決方案--------------------
$t = time();
echo date('北京時間 Y-m-d H:i:s', $t), '
';
date_default_timezone_set('Etc/GMT');
echo date('格林威治時間 Y-m-d H:i:s', $t), '
';

for($i=1; $i<=12; $i++) {
date_default_timezone_set("Etc/GMT-$i");
echo date("東 $i 區時間 Y-m-d H:i:s", $t), '
';
}
北京時間 2013-01-09 14:14:01
格林威治時間 2013-01-09 06:14:01
東 1 區時間 2013-01-09 07:14:01
東 2 區時間 2013-01-09 08:14:01
東 3 區時間 2013-01-09 09:14:01
東 4 區時間 2013-01-09 10:14:01
東 5 區時間 2013-01-09 11:14:01
東 6 區時間 2013-01-09 12:14:01
東 7 區時間 2013-01-09 13:14:01
東 8 區時間 2013-01-09 14:14:01
東 9 區時間 2013-01-09 15:14:01
東 10 區時間 2013-01-09 16:14:01
東 11 區時間 2013-01-09 17:14:01
東 12 區時間 2013-01-09 18:14:01

------解決方案--------------------
引用:
引用:用法:
Echo Fun::now('Y-m-d H:i:s',time());//2012-10-30 00:13:40
Echo Fun::now('Y-m-d H:i:s');//2012-10-30 00:13:40
Echo Fun::now();//1351527292
Echo time();//135152729……

因為我把這個new封裝進了Fun這個class裡了,你用的時候可以直接Echo now('Y-m-d H:i:s',time());//2012-10-30 00:13:40
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.