PHP Week to get code:
The code is as follows |
Copy Code |
Date ("L"); Data will be available for English week like Sunday Date ("W"); This can get a digital week like 123, note 0 is Sunday |
Get Chinese day of the week:
The code is as follows |
Copy Code |
$weekarray =array ("Day", "one", "two", "three", "four", "five", "six"); First define an array echo "Week". $weekarray [Date ("W")]; |
Get the specified date is:
The code is as follows |
Copy Code |
$weekarray =array ("Day", "one", "two", "three", "four", "five", "six"); echo "Week". $weekarray [Date ("W", "2011-11-11")]; |
PHP function date () Gets the current time
The code is as follows |
Copy Code |
<?php Echo $showtime =date ("y-m-d h:i:s");? > |
Output Current time: 2008-10-12 02:32:17
Strange, the actual time is: 2008-10-12 10:32:17
Look at the PHP manual, "Example 1." Date () example "One More time zone setting in the first line"
Set the default time zone to use. Available from PHP 5.1
The code is as follows |
Copy Code |
Date_default_timezone_set (UTC); |
Originally php5.1, the php.ini added date.timezone this option, by default is closed, that is, the display time (no matter what PHP command) is Greenwich Standard Time, and Beijing time is just 8 hours.
How can I set the right PHP time?
1, modify php.ini. Open php.ini Find Date.timezone Remove the preceding semicolon = Asia/shanghai, restart the Apache server can-the disadvantage is that if the program
put on someone else's server, can not modify php.ini, that is not.
2, add time to the program of the initialization of the statement of the "" "Date_default_timezone_set (" Asia/shanghai "); " This can be arbitrarily set by the programmer, my recommendation.
Time zone identifier, the values available in mainland China are: prc,asia/chongqing, Asia/shanghai, Asia/urumqi (China, Chongqing, Shanghai, Urumqi), etc/ Gmt-8,asia/harbin
Taiwan available: asia/macao, Asia/hong_kong, Asia/taipei (in sequence, Macau, Hong Kong, TAIPEI) and Singapore: Asia/singapore
It is time for Beijing to realize the output.