iT邦幫忙

DAY 1
3

遭遇PHP之經驗分享系列 第 1

[鐵人賽Day1]PHP timezone時區設置

想當初剛接觸PHP時,其中遇到的一個問題
在抓取系統時間,使用date()函數時出現以下錯誤:
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

如圖:

<?php
     echo date("H:m:s");
?>

經查詢,是php.ini檔的Date未設定時區

假如不想更改php.ini檔案,但需顯示其餘國家的時間,可以在程式碼內部設定
加入以下程式碼:date_default_timezone_set("Asia/Taipei");
(這邊是以台灣為示範)

經過實做,如下程式碼:

<?php
  date_default_timezone_set("Asia/Taipei");
  echo date("H:m:s");
?>

(參考資料:http://www.w3schools.com/php/php_date.asp)


下一篇
[鐵人賽Day2] GET/POST 的差異與配合PHP用法
系列文
遭遇PHP之經驗分享30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言