PHP date, strtotime, mktime processing

Source: Internet
Author: User
Tags iso 8601 iso 8601 format local time

Date (' y-m-d ', $time ());

Date (' y-m-d ', ' 1453996800 ');

Date (' y-m-d h:i:s ', ' 1453996800 ');

Date (' h:i ', ' 1453996800 ');

Date (' W ', ' 1453996800 '); Day of the week, the numbers represent 0 (Sunday) to 6 (Saturday), corresponding to moment (' 1453996800000 '). Format (' d ')

The date () function formats a local time/date.

Date (FORMAT,TIMESTAMP) format is required. Specifies how the results are returned. Timestamp is optional.

Day of the D month, 2 digits with leading zeros 01 to 31

The day of the D-week, the text says, 3 letters Mon to Sun
Day of the J month, without leading 1 to 31
L (Lowercase letter of "L") Day of the week, full text format Sunday to Saturday
N ISO-8601 format number represents the day of the week (PHP 5.1.0 new Plus) 1 (Monday) to 7 (Sunday)
S English suffix, 2 characters st,nd,rd or th, after the number of days per month. Can be used with J.
The day of the W week, the number represents 0 (Sunday) to 6 (Saturday)
Days 0 to 366 in the Z-year
The week of the year in W ISO-8601 format, starting from Monday (PHP 4.1.0 New) 42 (42nd Week of the year)
F month, full text format, such as January or March January to December
The month represented by the m number, with a leading 1 to 12
M three-letter abbreviation for month Jan to Dec
n number of months, without leading 1 to 12
t the number of days that a given month should be 28 to 31
L is a leap year if the leap year is 1, otherwise 0
o ISO-8601 format year number.
Y 4-digit year full representation for example: 1999 or 2003
Y 2 digits indicate the year for example: 99 or 03
A lowercase morning and afternoon value am or PM
A uppercase morning and afternoon value am or PM
B Swatch Internet Standard 000 to 999
G-hour, 12-hour format, without leading 1 to 12
G-hour, 24-hour format, without leading 00 to 23
H-hour, 12-hour format, with leading 1 to 12
H-hour, 24-hour format, with leading 000 to 23
I have a leading zero minute number 00 to 59>
S number of seconds, with leading 000 to 59>
E Time zone identifier (PHP 5.1.0 new) Example: Utc,gmt,atlantic/azores
I is daylight saving time if daylight saving time is 1, otherwise 0
O hours of difference from GMT for example: +0200
The difference between P and GMT (GMT) is separated by a colon between hours and minutes for example: +02:00
T the time zone where the machine is located
The number of seconds to offset the Z-time difference. The time zone offset in the west of UTC is always negative, and the east of UTC is positive. 43200 to 43200
Date in C ISO 8601 format (PHP 5 new Plus) 2004-02-12t15:19:21+00:00
R RFC 822 Format date For example: Thu, 2000 16:01:07 +0200
The number of seconds since the beginning of the Unix era (January 1 1970 00:00:00 GMT) time () get timestamp

Date (' y-m-d ', strtotime (' 2015-01-15 '));

Date (' y-m-d ', Strtotime (' +1 Day ', Strtotime (' 2015-01-15 ')));

Date (' y-m-d ', Strtotime ('-1 day ', Strtotime (' +1 month ', Strtotime (date (' y-m-01 ', (int) $endTime))));

Date (' y-m-d ', Strtotime ('-1 day ', Strtotime (' +1 year ', Strtotime (date (' y-01-01 ', (int) $endTime)))))

strtotime () resolves the date or time description of any English text to a Unix timestamp.

Strtotime (Time,now); time specifies the timing string to parse. Now is used to calculate the timestamp of the return value. If this argument is omitted, the current time is used.

The function expects to accept a string containing the U.S. English date format and attempt to resolve it to a Unix timestamp (the number of seconds from January 1 1970 00:00:00 GMT) whose value is relative to the time given by the now parameter, if this parameter is not provided, the current time of the system.

Date ("M-d-y", Mktime (0,0,0,12,36,2001)) = jan-05-2002

The Mktime () function returns a Unix timestamp for a date.
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
Hour is optional. Specified hours.
Minute is optional. Specify minutes.
Second is optional. Specify seconds.
Month is optional. Specifies the number of months to be represented.
Day is optional. Prescribed days.
Year is optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
IS_DST is optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1. since 5.1.0, the IS_DST parameter has been discarded. Therefore, you should use the new Time zone processing feature.

The parameter always represents the GMT date, so IS_DST has no effect on the result.
Parameters can be left-to-right and empty, and empty parameters will be set to the corresponding current GMT value.

PHP date, strtotime, mktime processing

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.