Php Date and Time addition and subtraction-PHP source code

Source: Internet
Author: User
Ec (2); php Date and Time addition and subtraction ** & nbsp; * time addition operation & nbsp; * @ paramint $ increment & nbsp; * @ paramstring $ unit & nbsp; * @ paramstring $ time format returned by returnFormat & nbsp; * @ returnvoid & nbsp; * & nbsp; publicf script ec (2); script

Php Date and Time addition and subtraction

/**
* Time Addition
* @ Param int $ increment
* @ Param string $ unit
* @ Param string $ time format returned by returnFormat
* @ Return void
*/
Public function add ($ increment, $ unit ='s ', $ returnFormat = NULL ){
$ Increment = intval ($ increment );
$ Source = $ this-> timestamp;
Switch ($ unit)
{
Case 'yy': $ result = $ source + $ increment *

31536000; break; // year
Case 'mm': $ result = $ source + $ increment *

2592000; break; // month
Case 'dd': $ result = $ source ++ $ increment * 86400;

Break; // day
Case 'H': $ result = $ source + $ increment * 3600;

Break; // hour
Case 'M': $ result = $ source + $ increment * 60;

Break; // minute
Default: $ result = $ source + $ increment;

Break; // second
}
If ($ returnFormat ){
$ Result = $ this-> format ($ returnFormat, $ result );
}
Return $ result;
}

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.