Learning points:
1.PHP date and time library
Dates and times are very different from most other types of data you encounter when programming in PHP.
Because date and time do not have a clear structure, and the calculation and representation of dates are also troublesome. In PHP, the date and time function library is a core part of the PHP language.
The total number of seconds since minute 00 seconds. Unix timestamps are not only used in Unix systems and Unix-like systems, but are also widely used in many other operating systems. For example (1184557366 means 2007-07-16 03:42:46)
Verification date: The checkdate() function can verify the date very well. If the provided date is valid, it returns true,
otherwise it returns false.
<?<span php </span><span if</span> (<span checkdate</span>(2,29,2007<span )) { </span><span echo</span> '日期合法'<span ; } </span><span else</span><span { </span><span echo</span> '日期不合法'<span ; } </span>?>
() function returns the string form of time and date formatted according to predefined instructions.
For all format parameters, please refer to the manual.
<?<span php </span><span echo</span> <span date</span>('Y-m-d H:i:sa'); <span //</span><span 直接输入日期和时间</span> <span echo</span> <span date</span>('今天的日期和时间为:Y/m/d H:i:sa'); <span //</span><span 可以插入无关的字符串</span> ?>
() function returns an associative number
group composed of elements related to the current time.
<?<span php </span><span print_r</span>(<span gettimeofday</span>()); <span //</span><span 可以传入一个真(1)</span> ?>
() function accepts a timestamp and returns an associative array consisting of its parts
. If no parameters are given, the current time and date are returned.
<?<span php </span><span print_r</span>(<span getdate</span>(1184557366<span )); </span>?>
() function can get the current timestamp and set the timestamp value.
Get a specific timestamp:
<?<span php </span><span echo</span> <span date</span>('Y-m-d H:i:s',<span time</span>()+(7*24*60*60<span )); </span>?>
() function can generate a timestamp for a given date and time.
Calculate time difference
<?<span php </span><span echo</span> <span mktime</span>(14,14,14,11,11,2007<span ); </span><span echo</span> <span date</span>('Y-m-d H:i:s',<span mktime</span>(14,14,14,11,11,2007<span )); </span>?>
Convert date to timestamp:
<?<span php </span><span $now</span> = <span time</span><span (); </span><span $taxday</span> = <span mktime</span>(0,0,0,7,17,2010<span ); </span><span echo</span> <span round</span>((<span $taxday</span> - <span $now</span>)/60/60<span ); </span>?>
() converts human-readable date to Unix timestamp.
Calculate time difference
<?<span php </span><span echo</span> <span strtotime</span>('2007-10-31 14:31:33'<span ); </span>?>
Get the last modification time of the current file:
<?<span php </span><span echo</span> (<span strtotime</span>('2007-10-31 14:31:33') - <span strtotime</span>('2007-10-31 11:31:33'))/60/60<span ; </span>?>
() can get the timestamp of the last modification time of the current file.
<?<span php </span><span echo</span> <span date</span>('Y-m-d H:i:s',<span getlastmod</span><span ()); </span>?>
:
Modify the settings in the php.ini file, find the;date.timezone = option under [date], and change this item todate .timezone=Asia/Shanghai, and then restart the apache server.
The
putenv
<?<span php </span><span putenv</span>('TZ=Asia/Shanghai'<span ); </span><span echo</span> <span date</span>('Y-m-d H:i:s'<span ); </span>?>
() can set the current default time zone.
date_default_timezone_get() can get the current default time zone.
<?<span php date_default_timezone_set(</span>'Asia/Shanghai'<span ); </span><span echo</span> <span date</span>('Y-m-d H:i:s'<span ); </span>?>
() function can get local time data and then return an array.
Calculate the page script running time:
<?<span php date_default_timezone_set(</span>'Asia/Shanghai'<span ); </span><span print_r</span>(<span localtime</span><span ()); </span><span print_r</span>(<span localtime</span>(<span time</span>(), <span true</span><span )); </span>?>
() function, which returns the current UNIX timestamp and microseconds. Returns
a string in the format msec sec, where sec is the current UNIX timestamp and msec is the number of microseconds.
Note: The article comes from Li Yanhui’s PHP video tutorial. This article is for communication only and may not be used for commercial purposes, otherwise you will be responsible for the consequences.
<?<span php </span><span function</span><span fntime() { </span><span list</span>(<span $msec</span>, <span $sec</span>) = <span explode</span>(' ', <span microtime</span><span ()); </span><span return</span> <span $msec</span>+<span $sec</span><span ; } </span><span $start_time</span> =<span fntime(); </span><span for</span>(<span $i</span>=0;<span $i</span><1000000;<span $i</span>++<span ) { } </span><span $end_time</span> =<span fntime(); </span><span echo</span> <span round</span>(<span $end_time</span> - <span $start_time</span>,4<span ); </span>?>
http://www.bkjia.com/PHPjc/759629.html
www.bkjia.com