No matter what kind of Web site to build, time is necessary to write, then about PHP timestamp programmer how much? Now I'm going to share with you a story about phpcms and PHP formatted timestamps of the article.
When building a station with Phpcms V9, the time tag is often used, it is the universal tag call-date time format, applicable to the whole station.
One, date time format display:
A\ Standard type: {date (' y-m-d h:i:s ', $rs [' Inputtime '])} output: 2013-01-31 13:15:10
B\ split: {date (' Y ', $rs [Inputtime]} year {date (' m ', $rs [Inputtime]} month {date (' d ', $rs [Inputtime])} Day output: January 31, 2013
C\ Extended Type:
{Date (' Y ', $inputtime);} 4-bit year output is: 2013 or 2014
{Date (' Y ', $inputtime);} 2-bit year output is: 10 or 11
{Date (' F ', $inputtime);} English month full name output is: January to December
{Date (' M ', $inputtime);} English month abbreviation output is: Jan to Dec
{date (' m ', $inputtime);} Leading 0 digit month output: 01 to 12
{Date (' n ', $inputtime);} Numeric month output: 1 to 12
{Date (' d ', $inputtime);} Leading 0-period output: 01 to 31
{Date (' J ', $inputtime);} The date output is: 1 to 31
{Date (' l ', $inputtime);} English week full name output: Sunday to Saturday
{Date (' D ', $inputtime);} English week abbreviation output is: Mon to Sun
{Date (' N ', $inputtime);} Format Numeric Week output: 1 to 7
{Date (' y-m-d h:i:s ', $rs [inputtime]+30*60)} Add some time after getting the article time
The PHP timestamp function gets the UNIX timestamp for the specified date
<?phpecho strtotime ("2017-6-27");? >
Results: 1498514400
Return June 27, 2017 0:0 0 seconds timestamp
1, php timestamp function to get the English text date and time examples are as follows:
Easy to compare, use date to convert time stamp to system time with specified timestamp
(1) Print the timestamp for tomorrow at this time Strtotime ("+1 Day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2017-6-27 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2017-6-27 09:40:25
(2) Print the timestamp at this time yesterday Strtotime ("-1 day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2017-6-27 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 day") Results: 2017-6-27 09:40:25
(3) Print timestamp strtotime ("+1 Week") at this time next week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2017-6-27 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2017-6-27 09:40:25
(4) Print timestamp strtotime ("1 week") at this time last week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2017-6-27 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 Week") Results: 2017-6-27 09:40:25
(5) Print the time stamp specified next week strtotime ("next Thursday")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2017-6-27 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2017-6-27 00:00:00
(6) Print the timestamp strtotime ("last Thursday") specified on the previous day of the week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday")) Results: 2017-6-27 00:00:00
The PHP timestamp Function example above shows that Strtotime can parse the datetime description of any English text into a Unix timestamp, and we get the specified timestamp by combining mktime () or date () format date time to achieve the required date time.
Example:
<?php//time stamp to date $date_time_array = getdate (1297845628);//1311177600 1316865566$hours = $date _time_array["hours"]; $minutes = $date _time_array["Minutes"]; $seconds = $date _time_array[" Seconds "]; $month = $date _time_array[" Mon "]; $day = $date _time_array[" Mday "]; $year = $date _time_array[" year "]; echo "Year: $year \nmonth: $month \nday: $day \nhour: $hours \nminutes: $minutes \nseconds: $seconds \ n"; Normal date turn timestamp echo mktime (0, 0, 0, 9, 18, 2011). "\ n"; Echo mktime (0, 0, 0, 9, 25, 2011). "\ n"; You can format this echo "Time () displays the day of the month and seconds:". Date ("Y-m-d h:i:s", Time ()). "\ n";//So even when the seconds show echo "Time () shows only the month Day:". Date ("Y-m-d", Time ()). " \ n "; Year only date echo "timestamp format:". Date ("Y-m-d h:i:s", 1297845628). "\ n"; The time stamp is used directly//the normal date is converted to timestamp, if sometimes seconds is the same, $year = ((int) substr ("2008-12-04", 0,4));//Get Year $month= ((int) substr (" 2008-12-04, 5,2);//Get Month $day= ((int) substr ("2008-12-04", 8,2));//Get the number of echo mktime (0,0,0, $month, $day, $year);?>
Parts to be aware of
< a >, PHP time large to divide into two, one is the timestamp type (1228348800), and the second is the normal date format (2008-12-4)
< two >, php5.1 above time stamp and actual time difference 8 hours, the solution is as follows
1, the simplest way is not to use php5.1 above version-obviously this is undesirable Method!!!
2, modify the php.ini. Open php.ini Find Date.timezone Remove the preceding semicolon = add Asia/shanghai After, restart Apache server can--the disadvantage is that if the program
Put on someone else's server, can not modify the php.ini, that will not be.
3, in the program to add time to initialize the statement that is: "Date_default_timezone_set (" Asia/shanghai "); ”
Time zone identifiers, the values available in mainland China are: prc,asia/chongqing, Asia/shanghai, Asia/urumqi (Chinese, Chongqing, Shanghai, Urumqi, respectively), Etc/gmt-8,asia/harbin
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei, respectively)
and Singapore: Asia/singapore
The article has ended, about phpcms and PHP format timestamp of the knowledge point to believe that we have some grasp of it, hope to help everyone.
Related recommendations:
How to generate millisecond timestamps in PHP
PHP timestamp (UNIX) usage detailed
PHP format timestamp display friendly time implementation ideas and code _php tips