Home  >  Article  >  Backend Development  >  Processing date and time with PHP (php tutorial for beginners)_PHP tutorial

Processing date and time with PHP (php tutorial for beginners)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:58:55830browse

This tutorial mainly talks about the following three points: Get the formatted date and time. Handles UNIX timestamps. Get date and time information. Calculation of dates. Verify the validity of the date.

php tutorial on handling date and time (php tutorial for beginners)
/*
This tutorial mainly talks about three points as follows

Get formatted date and time.
Handle unix timestamps.
Get date and time information.
Calculation of dates.
Verify the validity of the date.
*/
//Get formatted date and time

echo "Format current time
";
echo date('y-m-j');
echo "
";
echo "
";

echo "Today is the ".date('z')."day" of the year;
echo "
";
echo "
";

echo date('m web page effects,y l');
echo "
";
echo "
";

echo "Program execution time:".date('h:i:s');

//Processing unix timestamps.

echo "Timestamp".mktime(0,0,0,12,31,2007)."The corresponding date is:";
echo "
";

echo date("m-d-y", mktime(0,0,0,12,31,2007));
echo "


";
echo "
";

$day = 1;
echo "Timestamp".mktime(0,0,0,7,$day+38,2008)."The corresponding date is:
";
echo date("y-m-d", mktime(0,0,0,7,$day+38,2008));
echo "


";

//Get date and time information.

$time = mktime(20,0,0,8,8,2008);

echo "Date:".date("y-m-d h:i:s",$time)."";
echo "
";

echo "

";
echo "The relevant information for this date is as follows:";
echo "
";

$date = getdate($time);
print_r($date);

//Calculation of date.

$day = 1;
$month = 10;
$year = 1949;

$national_unix = mktime(0,0,0,$month,$day,$year);
$now_unix = time();
$national_time = $now_unix - $national_unix;

$national_day_year = floor($national_time/(365*24*60*60));
$national_day_day = floor($national_time/(24*60*60));

echo "www.bKjia.c0m 2008 has been ".$national_day_year." year";
echo "


";

echo "2008 has been ".$national_day_day." day"

//Verify the validity of the date.

if(checkdate(9,28,1980))
{
echo "7,22,1978 : "."This is a correct date format";
}
else
{
echo "This is not a correct date format";
}

echo "
";
echo "


";
echo "
";

if(checkdate(9,99,1999))
{
echo "This is a correct date format";
}
else
{
echo "9,99,1999 : "."This is not a correct date format";
}

/*
This tutorial mainly talks about the basic tutorial about PHP date and time, which is very useful for PHP beginners.
*/
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631363.htmlTechArticleThis tutorial mainly talks about the following three points to obtain the formatted date and time. Handles UNIX timestamps. Get date and time information. Calculation of dates. Verify the validity of the date. PHP tutorial processing...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn