PHP obtains the system time

Source: Internet
Author: User
Tags iso 8601 iso 8601 format
I saw someone writing on the Internet, but it was not very specific. I was a newbie, so I looked tired, so I carefully read the PHP Manual, then, I wrote the following text in the new way of thinking. The expression stringdate (string $ format [... SyntaxHighlighter. all ();

I saw someone writing on the Internet, but it was not very specific. I was a newbie, so I looked tired, so I carefully read the PHP Manual, then, I wrote the following text in the new way of thinking.

There are the following expressions:

Stringdate (string $ format [, int $ timestamp])

(Note: the person you just learned may not understand [, int $ timestamp]. In fact, this parameter represents an optional parameter, that is, you can enter it or not, this is not to say that this parameter is not required when the date function is executed, but has been assigned a value when it is defined. if the parameter is passed in, the default parameter such as date (int, int B = 1), where B has been defined)

(Note: $ format must be added with the $ symbol before it is changed in PHP)

First, let's talk about the function of the parameter $ timestamp, which represents the timestamp. A valid timestamp typically ranges from 20:45:54, January 1, December 13, 1901 to 03:14:07, January 1, January 19, 2038, Greenwich Mean Time. (The value range is the minimum and maximum values of 32-bit signed integers ). However, before PHP 5.1, this range was limited in some systems (such as Windows) from January 1-20, 1970 to January 19 (I tried it ).

Generally, it indicates the number of seconds represented by the benchmark + $ timestamp from 1970.1.1, that is, your current time. (In a single sentence, if it is hardware-oriented, the single-chip microcomputer has an RTC clock, that is, when the power supply is low, the 32768 crystal oscillator is used to start counting, and then the next time the single-chip machine starts to boot, the number of records read, converted to time .)

That is to say

Echo date ("Y-m-d h: I: s", 0 );
?>

12:00:00 will be displayed.

In the above formula, $ format has the following representation

Format
Day ------
D. The day of the month, which has two numbers from the leading zero, 01 to 31.
D. The day of the week. The text indicates the three letters Mon to Sun.
The day of month j, with no leading zeros 1 to 31
L ("L" lowercase letter) day of the week, complete text format Sunday to Saturday
N ISO-8601 format number represents the day of the week (PHP 5.1.0 plus) 1 (representing Monday) to 7 (representing Sunday)
The suffix of S after the number of days per month. it can contain 2 characters including st, nd, rd, and th. Can be used with j
The day of the week. The number indicates 0 (Sunday) to 6 (Saturday)
Day 0 to 366 in year z
Week ------
The week of the year in W ISO-8601 format, starting from Monday each week (new in PHP 4.1.0) for example: 42 (42nd weeks of the year)
Month ------
F month, complete text format, such as January or March January to December
The month represented by m numbers, with a leading zero from 01 to 12
M: The month Jan to Dec.
N indicates the month with no leading zeros 1 to 12.
T the number of days in a given month from 28 to 31
Year ------
L whether it is a leap year. if it is a leap year, it is 1; otherwise, it is 0.
O ISO-8601 format year number. This is the same as Y, except that the week number (W) of ISO belongs to the previous year or the next year. (New PHP 5.1.0) Examples: 1999 or 2003
The year in which the four digits of Y are complete, for example, 1999 or 2003.
The year represented by y two digits, for example, 99 or 03.
Time ------
A lower-case morning and afternoon values: am or pm
A capital value of AM and PM
B Swatch Internet standard: 000 to 999
G-hour, 12-hour format, no leading zero 1 to 12
G-hour, in 24-hour format, no leading 0 to 23
H-hour, 12-hour format, with a leading value of 0 to 12
H-Hour, in 24-hour format, with a leading zero 00 to 23
I have the number of minutes leading to zero from 00 to 59>
S seconds, with a leading zero 00 to 59>
Time zone ------
E time zone identifier (new in PHP 5.1.0) for example: UTC, GMT, Atlanta/Azores
When I is running or not, if it is running, it is 1; otherwise, it is 0.
O hours different from Greenwich Mean Time, for example: + 0200
The difference between P and Greenwich Mean Time (GMT). the hour and minute are separated by a colon (new in PHP 5.1.3), for example: +
T the Time zone of the local machine, for example, EST and MDT ([note] in Windows, the full text format, for example, "Eastern Standard Time", the Chinese version will display "China Standard Time ").
The number of seconds of the Z time difference offset. The time zone offset to the west of UTC is always negative, and the time zone offset to the east of UTC is always positive. -43200 to 43200
Complete date/time ------
Date in c ISO 8601 format (new PHP 5): 19: 21 + 00: 00
Date in RFC 822 format: Thu, 21 Dec 2000 16:01:07 + 0200
For the seconds since the Unix epoch (January 1 1970 00:00:00 GMT), see the time () example:
// Set the default time zone to use. Available in PHP 5.1
Date_default_timezone_set ('utc'); it is very important to set the time zone. the default time zone is 8 hours different from the Beijing time. date_default_timezone_set ('prc'); // PRC is Beijing time.


// The output is similar to Monday.
Echo date ("l ");

// The output is similar to: Monday 15th of August 2005 03:12:46
Echo date ('l dS \ of f y h: I: s ');

// Output: July 1, 2000 is on a Saturday
Echo "July 1, 2000 is on a". date ("l", mktime (0, 0, 0, 7, 1, 2000 ));

/* Use constants in format parameters */
// Output is similar to: Mon, 15 Aug 2005 15:12:46 UTC
Echo date (DATE_RFC822 );

// The output is similar to 2000-07-01T00: 00: 00 + 00: 00.
Echo date (DATE_ATOM, mktime (0, 0, 0, 7, 1, 2000 ));
?>

 


From the wolinxuebin column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.