2012-01-26 21 views
-1
日期和時間

我有一大堆的日期和時間存儲在一個MySQL表以下列格式爲簡單的字符串:字符串轉換爲在PHP

週二,2012年3月15日,

6 :下午30點- 8:00 PM。

我需要一種方法將它們轉換爲PHP日期和時間格式。

我想我可以使用爆炸得到日期格式相當容易,但我會如何做與時代相似的東西?

任何建議將是偉大的。謝謝。

+5

建議:使用搜索功能,因爲已經有5000+問如何格式化日期其他問題 – Gordon

回答

2

strtotime函數可能是您最好的解決方案。

http://php.net/manual/en/function.strtotime.php

<?php 
echo strtotime("now"), "\n"; 
echo strtotime("10 September 2000"), "\n"; 
echo strtotime("+1 day"), "\n"; 
echo strtotime("+1 week"), "\n"; 
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; 
echo strtotime("next Thursday"), "\n"; 
echo strtotime("last Monday"), "\n"; 
?>