PHP处理日期和时间(php入门者教程)
本教程主是讲三几点如下 获取格式化的日期和时间。 处理UNIX时间戳。 获取日期和时间的信息。 日期的计算。 验证日期的有效性。
php教程处理日期和时间(php入门者教程)
/*
本教程主是讲三几点如下
获取格式化的日期和时间。
处理unix时间戳。
获取日期和时间的信息。
日期的计算。
验证日期的有效性。
*/
//获取格式化的日期和时间
echo "格式化当前时间
";
echo date('y-m-j');
echo "
";
echo "
";echo "今天是一年中的第".date('z')."天";
echo "
";
echo "
";echo date('m 网页特效,y l');
echo "
";
echo "
";echo "程序执行时间:".date('h:i:s');
//处理unix时间戳。
echo "时间戳".mktime(0,0,0,12,31,2007)."对应的日期是:";
echo "
";echo date("m-d-y", mktime(0,0,0,12,31,2007));
echo "
";
echo "
";$day = 1;
echo "时间戳".mktime(0,0,0,7,$day+38,2008)."对应的日期是:
";
echo date("y-m-d", mktime(0,0,0,7,$day+38,2008));
echo "
";
//获取日期和时间的信息。
$time = mktime(20,0,0,8,8,2008);
echo "日期:".date("y-m-d h:i:s",$time)."";
echo "
";echo "
";<br> echo "该日期相关信息如下:";<br> echo "<br>"; <p>$date = getdate($time);<br> print_r($date);</p>
//日期的计算。
$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已经 ".$national_day_year." 年";
echo "
";echo "2008已经 ".$national_day_day." 天"
//验证日期的有效性。
if(checkdate(9,28,1980))
{
echo "7,22,1978 : "."这是一个正确的日期格式";
}
else
{
echo "这不是一个正确的日期格式";
}echo "
";
echo "
";
echo "
";if(checkdate(9,99,1999))
{
echo "这是一个正确的日期格式";
}
else
{
echo "9,99,1999 : "."这不是一个正确的日期格式";
}
/*
上在这篇教程主要是讲了关于php日期时间的基本教程哦,对php初学者很有用的。
*/
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools