我试图在用户添加条目时将时间保存在数据库中。每次运行time()函数时,它都会打印(或返回)1277155717,其中代表1969.php和1969中的时间函数
我想知道是否有一种方法可以将时间保存到数据库中,以表示今天的实际日期此时。
我使用
/* Works out the time since the entry post, takes a an argument in unix time (seconds) */
function time_since($original) {
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , 'year'),
array(60 * 60 * 24 * 30 , 'month'),
array(60 * 60 * 24 * 7, 'week'),
array(60 * 60 * 24 , 'day'),
array(60 * 60 , 'hour'),
array(60 , 'minute'),
);
$today = time(); /* Current unix time */
$since = $today - $original;
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since/$seconds)) != 0) {
// DEBUG print "<!-- It's $name -->\n";
break;
}
}
$print = ($count == 1) ? '1 '.$name : "$count {$name}s";
if ($i + 1 < $j) {
// now getting the second item
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
// add second item if it's greater than 0
if (($count2 = floor(($since - ($seconds * $count))/$seconds2)) != 0) {
$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
}
}
return $print;
}
为了显示分钟,年,月,等的数量,因为有人评论张贴的功能,它返回(40岁,6月前),当我通过函数time()的值;
“1277155717'的时间戳是'2010年6月21日星期一,21:28:37(GMT)' – vimist 2010-06-21 21:41:13
是的,那么上面的函数有什么问题(感谢验证这个btw) – user220755 2010-06-21 21:45:46
什么让你沉沦' 1277155717'在1969年有一段时间? – jigfox 2010-06-21 21:48:11