在PHP中将字符串转换为日期和时间

时间:2012-01-26 14:53:49

标签: php string date time

我将一大堆日期和时间存储在mySQL表中,作为以下格式的简单字符串:

2012年3月15日,星期二

下午6:30 - 晚上8点。

我需要一种方法将它们转换为PHP日期和时间格式。

我想我可以使用explode来轻松获取日期格式,但我会如何做与时俱作的事情呢?

任何建议都会很棒。感谢。

1 个答案:

答案 0 :(得分: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";
?>