[php]代码库
//时间戳转日期
$date_time_array = getdate(1297845628); //1311177600 1316865566
$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"];
echo "year:$year\nmonth:$month\nday:$day\nhour:$hours\nminutes:$minutes\nseconds:$seconds\n";
//正常日期转时间戳
echo mktime(0, 0, 0, 9, 18, 2011) . "\n";
echo mktime(0, 0, 0, 9, 25, 2011) . "\n";
/*
time();
是获得当前时间,但获得的是一整型
*/
//可以对此进行格式化
echo "time()显示年月日时分秒:" . date("Y-m-d H:i:s", time()) . "\n";
//这样连时,分秒一起显示
echo "time()只显示年月日:" . date("Y-m-d ", time()) . "\n"; //只年示年月日
echo "时间戳格式化:" . date("Y-m-d H:i:s", 1297845628) . "\n"; //直接使用时间戳
/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */