PHP Processing date and time (PHP beginner tutorial) _php Tutorial

Source: Internet
Author: User
Tags echo date
This tutorial is about three points to get the formatted date and time. Handles UNIX timestamps. Gets the date and time information. The calculation of the date. Validates the validity of the date.

PHP Tutorial Processing date and Time (PHP beginner tutorial)
/*
This tutorial is about three points as follows

Gets the date and time that was formatted.
Handles UNIX timestamps.
Gets the date and time information.
The calculation of the date.
Validates the validity of the date.
*/
Gets the formatted date and time

echo " formatting the current time
";
echo Date (' y-m-j ');
echo "
";
echo "
";

echo "Today is the first of the Year". Date (' Z '). " Days ";
echo "
";
echo "
";

echo Date (' m web effect, y l ');
echo "
";
echo "
";

echo "Program execution Time:". Date (' h:i:s ');

Handles 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 dates are:
";
echo Date ("Y-m-d", Mktime (0,0,0,7, $day +38,2008));
echo "";

Gets the 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 date related information is as follows:";
echo "
";

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

The calculation of the 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 already ". $national _day_year. " Years ";
echo "";

echo "2008 already ". $national _day_day. " Days

Validates 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 ";
}

/*
In this tutorial is mainly about the PHP date and time of the basic tutorial Oh, for beginners php very useful.
*/
?>

http://www.bkjia.com/PHPjc/631363.html www.bkjia.com true http://www.bkjia.com/PHPjc/631363.html techarticle This tutorial is about three points to get the formatted date and time. Handles UNIX timestamps. Gets the date and time information. The calculation of the date. Validates the validity of the date. PHP Tutorial Processing ...

  • 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.