日期:2014-05-17 浏览次数:20728 次
<?php
function getTime($date)
{
$mon = array(
'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'June'=> 6,
'July'=> 7,
'Aug' => 8,
'Sept'=> 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12
);
$m = substr($date, 0, strpos($date, '/'));
$good = str_replace($m, $mon[$m], $date);
// 返回整形的时间戳
return strtotime($good);
}
$date1 = "Apr/13/2012";
$date2 = "Apr/6/2012";
// 4月13号比4月16号大,结果为true
var_dump( getTime($date1) > getTime($date2) );
------解决方案--------------------
[User:liangdong Time:13:54:44 Path:~/php]$ php date.php
2012/7/2[User:liangdong Time:13:54:46 Path:~/php]$ cat date.php
<?php
function str_to_time($str_date) {
$mon_name = array(
"Jan", "Feb", "Mar",
"Apr", "May", "June",
"July", "Aug", "Sept",
"Oct", "Nov", "Dec"
);
$mon_index = range(1, 12);
$str_date = str_replace($mon_name, $mon_index, $str_date);
return $str_date;
}
echo str_to_time("2012/July/2");
?>
------解决方案--------------------
cat: cat: No such file or directory
<?php
function str_to_time($str_date) {
$mon_name = array(
"Jan", "Feb", "Mar",
"Apr", "May", "June",
"July", "Aug", "Sept",
"Oct", "Nov", "Dec"
);
$mon_index = range(1, 12);
$str_date = str_replace($mon_name, $mon_index, $str_date);
return @strtotime($str_date);
}
echo str_to_time("2012/July/2");
?>