<?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