Php retrieves the current time function

Source: Internet
Author: User

This article provides several php functions for getting the current time, such as date and time. It also shows me how to solve the time zone problem.

Php tutorial to obtain the current time function
This article provides several php functions for getting the current time, such as date and time. It also tells me how to solve the time zone problem.
Method 1 date function

Echo date ('Y-m-d h: I: s', time ());

// 2010-08-29 11:25:26

Method 2 time Functions

$ Time = time ();

Echo date ("y-m-d", $ time) // 2010-08-29

Method 3 $ _ server ['server _ time']

 

Method 4 strftime

Echo strftime ("% hh % m % a % d % B", time ());

18h24 Sunday 21 may

Another problem is the time zone. The default time difference between the php environment and the Beijing time is 8 hours. To get the correct time, you must set it.

Add date_default_timezone_set ('prc') at the beginning of the PHP file ');
Or in php. ini, date. timezone = prc; timeout.

Remember to modify php. ini to restart apache.

This site original tutorials Reprinted with the source of http://www.bkjia.com/phper/php.html


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.