<?php // Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the // Mountain Standard Time (MST) Time Zone$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm $today = date("m.d.y"); // 03.10.01 $today = date("j, n, Y"); // 10, 3, 2001 $today = date("Ymd"); // 20010310 $today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01 $today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day. $today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001 $today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month $today = date("H:i:s"); // 17:16:18 ?> 参看下php date API http://php.net/manual/en/function.date.php
他给我的时间格式就是这样的!'Sat May 14 22:35:44 +0800 2011'没见过这样的的格式啊,很变态啊
date('H:i:s',strtotime('Sat May 14 22:35:44 +0800 2011'));你吧你这个语句里的'H:i:s替换成上给的那些例子试下。看可以不可以。你可以先看下strtotime('Sat May 14 22:35:44 +0800 2011')后是不是日期。如果要字符串截取的话,这个字符应该是变长的吧!Sat May 5月周六 那如果是Sun July你不是麻烦了
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
参看下php date API http://php.net/manual/en/function.date.php
$time=explode(' ', $date);
echo $time[3];
如果格式是固定的话,应该能解决问题,当然有可能不是最好的解决方法,你们继续深入研究,有更好的解决方法记得告诉我!
; Defines the default timezone used by the date functions
;date.timezone =为 date.timezone = PRC 或者 在strtotime()前使用
date_default_timezone_set('PRC'); //设置为中华人民共和国时间$da = strtotime($strdate); //按+0800时区转换
然后在调用
date('H:i:s',$da);即可正确转换测试代码:<?
$str = 'Sat May 14 22:35:44 +0800 2011';
$current_timezone = date_default_timezone_get();
$strTtime = strtotime($str);
?>
<table border = '1'>
<caption>未设定时区前</caption>
<tr>
<td>时间字符串</td>
<td><?=$str?></td>
</tr>
<tr>
<td>当前时区</td>
<td><?=$current_timezone?></td>
</tr>
<tr>
<td>字符转化后日期格式('r Y')</td>
<td><?=date('r Y',$strTtime)?></td>
</tr>
<tr>
<td>字符转化后日期格式('H:i:s')</td>
<td><?=date('H:i:s',$strTtime)?></td>
</tr>
</table>
<br/></br>
<?
date_default_timezone_set('PRC');
$l_current_timezone = date_default_timezone_get();
$l_strTtime = strtotime($str);
?>
<table border = '1'>
<caption>设定时区PRC后</caption>
<tr>
<td>时间字符串</td>
<td><?=$str?></td>
</tr>
<tr>
<td>当前时区</td>
<td><?=$l_current_timezone?></td>
</tr>
<tr>
<td>字符转化后日期格式('r Y')</td>
<td><?=date('r Y',$l_strTtime)?></td>
</tr>
<tr>
<td>字符转化后日期格式('H:i:s')</td>
<td><?=date('H:i:s',$l_strTtime)?></td>
</tr>
</table>
PHP5+时也可以用
date_default_timezone_set('Asia/Shanghai'); 或者date_default_timezone_set('Asia/Chongqing'); 来设置中国的时区