PHP把26/09/2011 03:00pm转换成时间戳
<?php
$str = "26/09/2011 03:00pm";
$time = explode(" ", $str); //在空格处把字符串拆分成两个数组$time[0]="26/09/2011"和$time[1]="03:00pm"
$date = explode("/", $time[0]);//以/为分界把$time[0]="26/09/2011"分成$date[0]="$26"....
$re_date = "{$date[2]}-{$date[1]}-{$date[0]}";
$m = substr($time[1], -2, 2);
$temp_time = substr($time[1], 0, -2);
$temp_time .= ":00";
$re_time = strtotime("{$re_date} {$temp_time}");
if($m == "pm"){
$re_time = strtotime("+12 hour", $re_time);
}
echo $re_time."<p>";
echo date("Y-m-d",$re_time)."<br>";//以年月日格式输出
echo date("Y-m-d H:i:s",$re_time)."<p>";//这样连时分秒一起显示
$c=time()-$re_time;//$c就是两个时间间隔的秒数
echo floor($c/(60*60*24))."<br>";//两个时间戳间隔的天数,floor()函数是向下取整
?>
php得到当前周周一零点和周日24点的时间戳
<?php
function getmonsun(){
$curtime=time();
$curweekday = date('w');
//为0是 就是 星期七
$curweekday = $curweekday?$curweekday:7;
$curmon = $curtime - ($curweekday-1)*86400;
$cursun = $curtime + (7 - $curweekday)*86400;
$cur['mon'] = $curmon;
$cur['sun'] = $cursun;
return $cur;
}
$cur = getmonsun();
echo $mon = strtotime(date('Y-m-d',$cur['mon']));
echo "<br>";
echo $sun = strtotime(date('Y-m-d',$cur['sun']));
?>