PHP 怎樣取得本地化時間

來源:互聯網
上載者:User
PHP 怎樣取得本地化時間

 //本地時區標識符
 $timezone_identifier = "Asia/Hong_Kong";
//設定用於一個指令碼中所有日期時間函數的本地預設時區
 date_default_timezone_set($timezone_identifier);
 $aToday = getdate();

這樣就可以取得本地區日期時間 因為預設取得是格林威治時間0時區
也可以設定php.ini
[Date]
; Defines the default timezone used by the date functions
date.timezone =
"Asia/Hong_Kong"

重新啟動apache
 $aToday = getdate();
這樣就可以取得本地區日期時間  我使用time()和getdate()函數得到的時間和系統時間不同,請教高手,My Code如下:

<?php
  $timestamp=time();
  echo $timestamp."<br>";
  $date_time_array=getdate($timestamp);
  $datetime=$date_time_array["year"]."-".$date_time_array["mon"]."-".$date_time_array["mday"]." ";
  $datetime=$datetime.$date_time_array["hours"].":".$date_time_array["minutes"].":".$date_time_array["seconds"];
  echo $datetime;
?>

輸入內容為:
1142992778
2006-3-22 1:59:38

int time(void)
是返回當前的 時間戳記,即從1970年1月1日00:00:00到當前的秒數
而 array getdate(int[timestamp])是根據timestamp返回的日期和時間的資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.