欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php获取当前日期

程序员文章站 2022-05-27 20:42:41
...

// 将目前的时间戳值放入一数组内 $strdate = '2014-02-03'; $desDate = strtotime($strdate); //var_dump($desDate); $timestamp = time(); //echo "\noriginalDate:".date('Y-m-d',time())."\n"; echo "\noriginalDate:".date('Y-m-d',$desDate)."\n"; //$


// 将目前的时间戳值放入一数组内
$strdate = '2014-02-03';
$desDate = strtotime($strdate);
//var_dump($desDate);

$timestamp = time();
//echo "\noriginalDate:".date('Y-m-d',time())."\n";
echo "\noriginalDate:".date('Y-m-d',$desDate)."\n";


//$date_time_array = getdate($timestamp);
$date_time_array = getdate($desDate);
$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];
// 用mktime()函数重新产生Unix时间戳值减7天
$timestamp = mktime($hours, $minutes, $seconds, $month, $day-7, $year);
echo "\naddSevenDate:".date('Y-m-d',$timestamp)."\n";


echo "\n------\n";
$yestertime = date ( 'Y-m-d', strtotime("-7 day",$desDate) );
echo "maethod2:".$yestertime;