The Date/time function allows you to extract and format the date and time on the server. These functions depend on the local settings of the server.
Let's introduce the following time () function:
Time () function
The time () function returns the Unix timestamp for the current time. Returns the number of seconds since the Unix era (January 1, 1970 00:00:00 GMT) to the current time.
The timestamp of the time the request was initiated was saved in $_server[' Request_time ' from PHP 5.1.
Echo (Date ("D F D Y", $time)); >
Program Run Result:
1292984702Wed December 22 2010
1292984702 units are seconds, from January 1, 1970 00:00:00 to the current number of seconds.
Sometimes we want to know what's going on in the next week, such as the number of days, the day of the week, and so on, we can write:
Echo ' Next Week: '. Date (' y-m-d d ', $nextWeek). "
";? >
Program Run Result:
Now:2010-12-22next week:2010-12-29 Wed
Date () function
This function is more familiar.
"); Echo (Date (" L ")."
"); Echo (Date (" L DS of F Y h:i:s A ")."
"); Echo (" Oct 3,1975 is on a ". Date (" L ", Mktime (0,0,0,10,3,1975))."
"); Echo (Date (date_rfc822)."
"); Echo (Date (Date_atom,mktime (0,0,0,10,3,1975)).
"); Echo (" Result with Gmdate ():
"); Echo (Gmdate (" L ")."
"); Echo (Gmdate (" L DS of F Y h:i:s A ")."
"); Echo (" Oct 3,1975 is on a ". Gmdate (" L ", Mktime (0,0,0,10,3,1975))."
"); Echo (Gmdate (date_rfc822)."
"); Echo (Gmdate (Date_atom,mktime (0,0,0,10,3,1975)).
");? >
Program Run Result:
Result with date (): Wednesdaywednesday 22nd of December 02:36:18 Amoct 3,1975 is on a fridaywed, Dec 10 02:36:18 + 00001975-10-03t00:00:00+00:00result with Gmdate (): Wednesdaywednesday 22nd of December, 02:36:18 AMOct 3,1975 was on a fridaywed, 02:36:18 +00001975-10-03t00:00:00+00:00
Therefore, we should give a compatibility of the wording, unified use of gmdate, and manually set the current time zone, the following improvements:
echo gmdate (' y-m-d h:i:s ', time () + 3600 * 8);
So no matter under the Linux+apache or windows are getting the correct results, of course, there is a benefit to write, when the site is facing the world, then the site users as long as the settings in the time zone, the program automatically based on the time zone set by the user to calculate, The publication time of the information in the database is only the time that is generated by the current date (), then the published time in China + 8 time zone is: 2007-03-14 12:15:27, then in Europe + 2 time zone users see this information published: 2007-03-14 06:15:27, the time for this information is all right.
http://www.bkjia.com/PHPjc/752563.html www.bkjia.com true http://www.bkjia.com/PHPjc/752563.html techarticle The Date/time function allows you to extract and format the date and time on the server. These functions depend on the local settings of the server. First introduce the time () function: Time () function time () function return ...