如何在日期函数第一个参数中附加一个字符串?

时间:2013-05-11 14:32:25

标签: php date

我有以下代码

$date = '2013-05-11 07:10:14';

echo date('F j, Y at h:i a', strtotime($date); //Not work;  May 11, 2013 at 7:10 am

echo date('F j, Y h:i a', strtotime($date); // This will work when avoiding the `at` from date function.

我正在尝试在日期函数中附加字符串以将上述日期显示为May 11, 2013 at 7:10 am。如何使用预建日期函数以此格式创建日期?

2 个答案:

答案 0 :(得分:1)

尝试转义at字符串,

echo date('F j, Y \a\t h:i a', strtotime($date));

<强> DEMO.

答案 1 :(得分:1)

您需要转义任何也是格式化队列的字母。您必须双重转义“t”,因为\t是制表符。

echo date('F j, Y \a\\t h:i a');

See it in action