PHP Date function fetch time several examples

Source: Internet
Author: User
Tags add time current time ini what php

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.

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.