2009年8月6日 星期四

[php] strtotime 多種方法.

code:
$t = '2009-07-20 05:04:25';
echo $t."\n";
echo strtotime( $t)."\n";
echo date('Y-m-d H:i:s',strtotime( $t))."\n";
result:
2009-07-20 05:04:25
1248037465
2009-07-20 05:04:25


code:
$t = 'Nov 11 2008 12:00AM';
echo $t."\n";
echo strtotime( $t)."\n";
echo date('Y-m-d H:i:s',strtotime( $t))."\n";

result:
Nov 11 2008 12:00AM
1226332800
2008-11-11 00:00:00


還有另一種方法...
function gettime($str)
{
$temp=explode("-",str_replace(array(":"," "),"-",trim($str)));
return mktime($temp[3],$temp[4],$temp[5],$temp[1],$temp[2],$temp[0]);
}
$str="2006-12-26 23:19:34";
$tem=gettime($str);
echo $tem;

【下列文章您可能也有興趣】

沒有留言: