Time and date 1 and date () functions in PHP
String date (string $ format [, int $ timestamp])
Purpose: setTimestampFormatted as a readable time and date.
Parameter description
Format |
Required. The format of the specified timestamp. |
Timestamp |
Optional. The specified timestamp. The default value is the current time and date. |
1. get date (1), year
Format example
L |
Is it a leap year? |
If the leap year is 1, otherwise it is 0 |
O |
The number of years in ISO-8601 format. 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 |
Y |
The year in which the four digits represent the complete number. |
Example: 1999 or 2003 |
Y |
A two-digit year |
Example: 99 or 03 |
(2) month
Format example
F |
The month in the complete text format, such as January or March. |
January to December |
M |
Number indicates the month, with a leading zero |
01 to 12 |
M |
The month abbreviated to three characters. |
Jan to Dec |
N |
Number indicates the month, with no leading zero |
1 to 12 |
T |
Number of days in a given month |
28 to 31 |
(3), Day
Format example
D |
The day of the month, which has two digits leading to zero |
01 to 31 |
D |
The day of the week. The text indicates three letters. |
Mon to Sun |
J |
The day of the month, with no leading zero |
1 to 31 |
L (lowercase letters of "L) |
Day of week, complete text format |
Sunday to Saturday |
N |
The day of the week represented by a number in the ISO-8601 format (new in PHP 5.1.0) |
1 (Monday) to 7 (Sunday) |
S |
English suffix after the number of days per month, 2 characters |
St, nd, rd or th. Can be used with j |
W |
The day of the week, represented by a number |
0 (Sunday) to 6 (Saturday) |
Z |
The day of the year. |
0 to 365 |
(4), Week
Format example
W |
The week of the year in ISO-8601 format, starting from Monday each week (new in PHP 4.1.0) |
Example: 42 (42nd weeks of the current year) |
2. obtain time (1) and time
Format example
A |
Morning and afternoon values in lower case |
Am or pm |
A |
Upper-case morning and afternoon values |
AM or 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 zero |
0 to 23 |
H |
Hour, 12-hour format, with leading zero |
01 to 12 |
H |
Hour, in 24-hour format, with a leading zero |
00 to 23 |
I |
Minutes with a leading zero |
00 to 59> |
S |
Number of seconds, with a leading zero |
00 to 59> |
U |
Millisecond (new in PHP 5.2.2 ). Note that the date () function always returns 000000 because it only accepts integer parameters, while DateTime: format () supports milliseconds. |
Example: 654321 |
(2) time zone
Format example
E |
Time zone ID (new in PHP 5.1.0) |
Example: UTC, GMT, Atlanta/Azores |
I |
When it is enabled or not |
If this parameter is set to 1, otherwise it is set to 0. |
O |
Hours different from Greenwich Mean Time |
For example: + 0200 |
P |
Difference from Greenwich Mean Time (GMT), separated by colons between hours and minutes (new in PHP 5.1.3) |
Example: + |
T |
Time zone of the local machine |
For example, EST and MDT are in full text format in Windows. for example, "Eastern Standard Time" is displayed in Chinese "). |
Z |
The number of seconds of the 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 |
II. mktime () function
Mktime (hour, minute, second, month, day, year)
Purpose: return the Unix timestamp based on the given parameters.
The timestamp is a long integer that contains the number of seconds from the Unix epoch (January 1 1970 00:00:00 GMT) to the given time.
3. strtotime () function
Int strtotime (string $ time [, int $ now = time ()])
Purpose: resolve the date and time descriptions of any English text to Unix timestamps.
Time: Date/time string. For details about the correct format, see date and time format.
Now: The timestamp used to calculate the return value.
Note: modify the time zone to get the local time
- ModifyPHP. iniFileDate. timezoneField
Remove the semicolon, add PRC (Beijing Time) to the end, and restart appache.
- Initialization time in codeDate_default_timezone_set (XXX)
- In addition, for XXX, the available values in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence)
Hong Kong and Taiwan regions are available: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei ). Singapore: Asia/Singapore.
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
4. provide a simple calendar after I finish learning this:
";}For ($ j = 0, $ I = date (" w ", strtotime (" 2015/$ MONTH/01 "); $ I <= 6; $ I ++, $ j ++) {$ tmp = 01 + $ j; $ GLOBALS ['satnum'] = $ tmp; echo"
Copyright Disclaimer: This article is an original Lshare article. if you need to reprint it, please contact me. if you have any questions, please comments or private messages.
Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
"; For ($ I = 0; $ I
$ Tmp | ";} Echo"
"; For ($ j = 0; $ j <4; $ j ++) {echo"
"; For ($ I = 0; $ I <7; $ I ++) {$ tmp = ++ $ GLOBALS ['satnum']; if ($ tmp = date ("d") echo"
$ Tmp | "; Elseif (! ($ Tmp> date ("t") echo"
$ Tmp | ";} Echo"
";}?> ";?>