<?php
$a = 'MAY 05, 2001 00:54:00 AM';
echo date('Y-m-d',strtotime($a)).'<br />';
$b = 'MAY 05, 2001 05:54:00 AM';
echo date('Y-m-d',strtotime($b)).'<br />';
//MAY 05, 2001 00:54:00 AM return 1970-01-01
//MAY 05, 2001 05:54:00 AM return 2001-05-05
?>
回答
您已通过AM在24小时时间format.I已经纠正它
$a = 'MAY 05, 2001 00:54:00';
echo date('Y-m-d',strtotime($a)).'<br />';
$b = 'MAY 05, 2001 05:54:00 AM';
echo date('Y-m-d',strtotime($b)).'<br />';
的AM
意味着你使用的是12-hour clock。然而,在这个时钟系统中没有“零小时”,所以你的第一个例子00:54:00 AM
不是有效的时间(12小时时钟从一到十二,然后翻转回am/pm切换到一个)。也许你的意思只是00:54:00
(24小时制)或12:54:00 AM/PM
(这将在一点之前6分钟)。
并非如此:<?php $ a ='2013年8月22日03:60:00'; $ b ='AUG 29,2013 04:60:00 PM'; echo date('Y-m-d H:i:s',strtotime($ a))'。'
'; echo date('Y-m-d H:i:s',strtotime($ b))'。'
'; ?> –
miket
2012-03-20 06:51:48
@miket:那些日期也是无效的,因为第六十分钟没有这样的事情。 “04:59:00”之后的分钟将是“05:00:00”,而不是“04:60:00”。一些非常宽松的日期/时间解析器可能会接受像您提供的示例那样古怪的格式,但它很自然会被拒绝。 – 2012-03-20 07:26:16
谢谢,我明白了。 – miket 2012-03-20 07:53:08
,如果您使用的是PHP版本高于5.3.0可以使用
http://www.php.net/manual/tr/function.date-parse-from-format.php
像
$a = 'MAY 05, 2001 00:54:00';
echo date('Y-m-d',date_parse_from_format("F d, Y H:i:s",$a)).'<br />';
- 1. PHP strtotime返回不同值的Mysql UNIX_TIMESTAMP
- 2. php`strtotime`变量不返回负数?
- 3. PHP - strtotime返回3位数字太短?
- 4. PHP strtotime返回错误结果
- 5. PHP的strtotime()函数返回的空白/ 0
- 6. PHP strtotime和JavaScript Date.parse返回不同的时间戳
- 7. PHP strtotime和mktime返回不同的结果
- 8. php strtotime函数没有返回正确的日期
- 9. PHP strtotime在日期列为空时返回1970年的日期
- 10. PHP的strtotime EST来回转换
- 11. PHP strtotime全年而不是一天返回
- 12. strtotime总是返回01-1-1970
- 13. PHP的strtotime发出
- 14. php - mktime或strtotime?
- 15. PHP strtotime和DST
- 16. PHP strtotime问题
- 17. php date&strtotime
- 18. PHP函数strtotime
- 19. strtotime php mysql
- 20. php strtotime反向
- 21. PHP strtotime timezone
- 22. Javascript的等效PHP的strtotime()?
- 23. php codeigniter - strtotime错误
- 24. Wordpress php/strtotime问题
- 25. PHP strtotime函数quandry
- 26. PHP的strtotime上周每天
- 27. PHP的strtotime问题分钟
- 28. 替代的strtotime在PHP 5.1.6
- 29. php strtotime“上个星期五2012年4月”上周五没有返回
- 30. 日期的strtotime()计算返回1969年日期
所以你想做的事..你没有告诉你确切需要 – Rafee 2012-03-20 06:45:03
<?php $ a ='AUG 09,2013 08:13:00 PM'; echo date('Y-m-d H:i:s',strtotime($ a))'。'
'; // return 2013-08-09 20:13:00 $ b ='AUG 29,2013 04:60:00 PM'; echo date('Y-m-d H:i:s',strtotime($ b))'。'
'; // return 1970-01-01 07:00:00 ?> that'it – miket 2012-03-20 07:00:37
你想在这里显示小时/分钟/秒..你显示的代码工作良好..什么是错的 – Rafee 2012-03-20 07:04:10