Php output time difference

Source: Internet
Author: User
: This article mainly introduces the php output time difference. if you are interested in the PHP Tutorial, you can refer to it. Use strtotime ("-1 day") for the test ");

The previous day of today, that is, yesterday. Today is determined based on the current Unix time cut.

Date_default_timezone_set ('prc'); // Default time zone
Echo "today:", date ("Y-m-d", time ()),"
";
Echo "today:", date ("Y-m-d", strtotime ("18 Jun 2008 ")),"
";
Echo "yesterday:", date ("Y-m-d", strtotime ("-1 day ")),"
";
Echo "tomorrow:", date ("Y-m-d", strtotime ("+ 1 day ")),"
";
Echo "one week later:", date ("Y-m-d", strtotime ("+ 1 week ")),"
";
Echo "one week, two days, four hours, two seconds later:", date ("Y-m-d G: H: s ", strtotime ("+ 1 week 2 days 4 hours 2 seconds ")),"
";
Echo "next Thursday:", date ("Y-m-d", strtotime ("next Thursday ")),"
";
Echo "last Monday:". date ("Y-m-d", strtotime ("last Monday "))."
";
Echo "a month ago:". date ("Y-m-d", strtotime ("last month "))."
";
Echo "one month later:". date ("Y-m-d", strtotime ("+ 1 month "))."
";
Echo "Ten years later:". date ("Y-m-d", strtotime ("+ 10 year "))."
";
?>

// Interval several minutes before or after
Function GetMinute ($ Minu, $ type = 'l ')
{
If (! Strcmp ($ type, 'B '))
$ Res = date ("Y-m-d H: I: s", strtotime ("-$ Minu minute "));

Else $ res = 0;
If (! Strcmp ($ type, 'L '))
$ Res = date ("Y-m-d H: I: s", strtotime ("+ $ Minu minute "));

Else $ res = 0;
Return $ res;
}
// Time before or after several seconds
Function GetSec ($ sec, $ type = 'l ')
{
If (! Strcmp ($ type, 'B '))
$ Res = date ("Y-m-d H: I: s", strtotime ("-$ sec second "));

Else $ res = 0;
If (! Strcmp ($ type, 'L '))
$ Res = date ("Y-m-d H: I: s", strtotime ("+ $ sec second "));

Else $ res = 0;
Return $ res;
}

The above introduces the php output time difference, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.