PHP code example to get system time

WBOY
Release: 2016-07-25 08:59:00
Original
972 people have browsed it
  1. //Method 1

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

  3. //Method 2

  4. date_default_timezone_set( 'Asia/Chongqing'); //The system time difference is 8 hours.
  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. ?>
Copy the code

The letters in the date function represent meaning: a - "am" or "pm" A - "AM" or "PM" B - Swatch Internet Time d - Day of the month, 2 digits with leading zeros, e.g. "01" to "31" D - day of the week, text, 3 letters, e.g. "Fri" F - month, complete text format, such as "January" g - hour, in 12-hour format, without leading zeros, e.g. "1" through "12" G - hour, in 24-hour format, without leading zeros, e.g. "0" through "23" h - Hour, 12-hour format, such as "01" to "12" H - Hour, 24-hour format, such as "00" to "23" i - minute, for example "00" to "59" I (uppercase letter "i") - "1" if it's daylight saving time, "0" otherwise j - The day of the month, without leading zeros, such as "1" through "31" l (lowercase "L") - Day of the week, in full text format, such as "Friday" L - Boolean value indicating whether it is a leap year, such as "0" or "1" m - month, for example "01" to "12" M - Month, text representation, 3 letters, e.g. "Jan" n - month, without leading zeros, e.g. "1" through "12" O - the number of hours from Greenwich Mean Time, for example "+0200" r - Date in RFC 822 format, such as "Thu, 21 Dec 2000 16:01:07 +0200" (new in PHP 4.0.4) s - number of seconds, for example "00" to "59" S - English suffix after the day of the month, 2 characters, such as "st", "nd", "rd" or "th" t - the number of days in a given month, e.g. "28" to "31" T - The time zone where this machine is located, such as "EST" or "MDT" ([Translator's Note] In complete text format under Windows, such as "Eastern Standard Time", the Chinese version will display "China Standard Time".) U - Number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT) w - Day of the week as a number, e.g. "0" (Sunday) to "6" (Saturday) W - Week number of the year in ISO-8601 format, each week starts on Monday (new in PHP 4.1.0) Y - year, 4 digits, for example "1999" y - annual fee, 2 digits, e.g. "99" Z - The time offset in seconds (for example, "-43200" to "43200"). Time zone offsets west of UTC are always negative, and time zone offsets east of UTC are always positive.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!