PHP date does not fully complement 0 instance program code

Source: Internet
Author: User

$time = ' 2010-1-11 ';

Define a day I turn it into the 2010-01-1

$splitDate = Explode ("-", $time);

Split to "-" separate

$stime = Mktime (0,0,0, $splitDate [1], $splitDate [2], $splitDate [0]);

And then use Mktime to convert it into a time load.

if (Intval ($splitDate [1]) <10 && substr ($splitDate [1],0,1)!= ' 0 ')
{
$splitDate [1] = ' 0 '. $splitDate [1];
}
To divide a number of months to determine if it is 01 this format does not operate otherwise add a 0

if (Intval ($splitDate [2]) <10 && substr ($splitDate [2],0,1)!= ' 0 ')
{
$splitDate [2] = ' 0 '. $splitDate [2];
}
To do the same for the date, less than 10 to fill 0

/*
Function Analysis:
Explode uses one string to split another string array explode (string separator, string string [, int limit])
The <a href=/phper/21/101d7c9a91356a428c8039c03dd4500b.htm>mktime</a> function returns a Unix timestamp for a date. Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
<a href=/phper/18/9351c693420d88336920eb2c12fca245.htm>intval</a> int intval (mixed var [, int base])
Returns the integer value of the variable var by using a specific binary conversion (the default is decimal).

The SUBSTR function returns part of the string substr (string,start,length)

*/
?>

Site original tutorial, reprinted annotated from Www.111cn.net

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.