PHP Date and time

Source: Internet
Author: User
Tags echo date idate local time

Get time

1. Use the DATE function to format a local time.

Output Current Time

echo Date (' y-m-d h:i:s ');

2. Use the GETDATE function to get datetime information for the timestamp.

Print out detailed information

Var_dump (GETDATE (Time ()));


Time stamp

1. Use the time function to get the current timestamp

Output the current timestamp

Echo Time ()

2. Use the Mktime function to convert the datetime into a timestamp.

Parameters last, minute, second, month, day, year

Echo Mktime (10, 10, 10, 10, 10, 2005);


Time zone settings

1. Use the Date_default_timezone_get function to get the current time zone

Gets the default time zone of UTC

Echo Date_default_timezone_get ();

2. Use the Date_default_timezone_set function to set the current time zone

Set current time zone for Asia/Shanghai

Date_default_timezone_set (' Asia/shanghai ');

Time to output the current time zone

echo Date (' y-m-d h:i:s ')


Verify Date

1. Use the Checkdate function to verify.

Verification: Month, day, year is legal

Echo checkdate (15, 10, 2015)

Get more Time

1. Use the Gettimeofday function to get the current time

Output Schedule

Var_dump (Gettimeofday ());

2. Use the Strtotime function to convert the datetime into a timestamp.

Get timestamp by date time

echo strtotime (' 2015-10-10 10:10:10 ');

3. Use the Idate function to accept only one format string generation time.

Accept only one formatted string

echo idate (' Y ');

4. Use the Microtime function to get the timestamp and the number of microseconds.

Output microseconds and timestamps

Echo Microtime ();


PHP Date and time

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.