PHP Date and Time functions

Source: Internet
Author: User
Tags echo date time and date

1. Time zone settings

Method One: Set the Date.timezone=asia/hong_kong of the php.ini, so that the system default time is East 8 zone

Method Two: Use the function Date_default_timezone_set () to set the time zone to Date_default_timezone_set ("Asia/hong_kong")

2. Get the current timestamp

Use the time () function to return the current time and date directly, and the timestamp represents the number of seconds from January 1, 1970 0:0 0 seconds to the time of the program's Run

3. Get the current date and time

Use the date () function to return the current date. Date () has many parameters, such as using "D" to return the date of the current month 01 to 31

4. Resolve date and time to UNIX timestamp

Use the Maketime () function to generate the appropriate UNIX timestamp


Let's look at an example:
<?php

Date_default_timezone_set ("Asia/hong_kong");

$timefuture = Mktime (0,0,0,01,01,2016);
$timenow = time ();
$timecount = $timefuture-$timenow;
$day = Round ($timecount/86400);

echo Date ("Current time: Y year M D Day [L]h point I min s second", $timenow). " <br> ";
echo "is also available from January 1, 2016". $day. " Days. "." <br> ";


?>

The result of the operation is:


PHP date and time functions

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.