Home  >  Article  >  php教程  >  php获取当前日期

php获取当前日期

WBOY
WBOYOriginal
2016-06-06 19:43:351273browse

// 将目前的时间戳值放入一数组内 $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;

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
Previous article:php教程一,变量Next article:php如何随机显示图片