Heim  >  Artikel  >  Backend-Entwicklung  >  php获取系统时间的代码举例

php获取系统时间的代码举例

WBOY
WBOYOriginal
2016-07-25 08:59:00971Durchsuche
  1. //方法1

  2. echo date("Y-m-d h:i:s");
  3. //方法2

  4. date_default_timezone_set('Asia/Chongqing'); //系统时间差8小时问题
  5. $now = getdate(time());
  6. $cur_wday=$now['wday'];
  7. $date = date("Y-m-d H:i:s $cweekday[$cur_wday]");
  8. echo $date;
  9. //by bbs.it-home.org
  10. ?>
复制代码

date函数中字母代表的含义: a - "am" 或 "pm" A - "AM" 或 "PM" B - Swatch Internet Time d - 月份中的第几天,有前导零的 2 位数字,例如 "01" to "31" D - 星期中的第几天,文本表示,3 个字母,例如 "Fri" F - 月份,完整的文本格式,例如 "January" g - 小时,12 小时格式,没有前导零,例如 "1" 到 "12" G - 小时,24 小时格式,没有前导零,例如 "0" 到 "23" h - 小时,12 小时格式,例如 "01" 到 "12" H - 小时,24 小时格式,例如 "00" 到 "23" i - 分钟,例如 "00" 到 "59" I(“i”的大写的字母)- 如果是夏令时则为 "1",否则为 "0" j - 月份中的第几天,没有前导零,例如 "1" 到 "31" l(“L”的小写字母)- 星期中的第几天,完整的文本格式,例如 "Friday" L - 布尔值表示是否为闰年,例如 "0" 或者 "1" m - 月份,例如 "01" to "12" M - 月份,文本表示,3 个字母,例如 "Jan" n - 月份,没有前导零,例如 "1" 到 "12" O - 与格林威治时间相差的小时数,例如 "+0200" r - RFC 822 格式的日期,例如 "Thu, 21 Dec 2000 16:01:07 +0200"(PHP 4.0.4新增) s - 秒数,例如 "00" 到 "59" S - 每月天数后面的英文后缀,2 个字符,例如 "st","nd","rd" 或者 "th" t - 给定月份所应有的天数,例如 "28" 到 "31" T - 本机所在的时区,例如 "EST" 或 "MDT"(【译者注】在 Windows 下为完整文本格式,例如“Eastern Standard Time”,中文版会显示“中国标准时间”。) U - 从 Unix 纪元(January 1 1970 00:00:00 GMT)开始至今的秒数 w - 星期中的第几天,数字表示,例如 "0"(星期天)到 "6" (Saturday) W - ISO-8601 格式年份中的第几周,每周从星期一开始(PHP 4.1.0 新加的) Y - 年份,4 位数字,例如 "1999" y - 年费,2 位数字,例如 "99" Z - 时差偏移量的秒数(例如 "-43200" 到 "43200")。UTC 西边的时区偏移量总是负的,UTC 东边的时区偏移量总是正的。



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn