如何显示月份、当天和当前时间加十二小时


How to Display the Month, Day of the Month, and Current Time Plus Twelve Hours?

我正在寻找有关我的PHP代码的帮助:

$date = date('m/d/Y h:i:s a', time());
echo "The current server timezone is: " . $date;
$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
echo(jddayofweek($jd,1)); 

目前该输出:

The current server timezone is: 03/28/2014 01:27:17 pm Friday

我正在尝试将此显示为当前月份、当天以及当前时间加上12小时。例如,输出为:

 The current server timezone is: March 28 Friday at 1:27 am Friday

如果有人能帮忙,我们将不胜感激。谢谢你的帮助。

在OOP风格中:

$dateTime = new DateTime('now');
$dateTime->add(new DateInterval('PT12H'));
echo $dateTime->format('F j l 'a''t h:i a l');

或者只使用DateTime:

$dateTime = new DateTime('+12 hours');
echo $dateTime->format('F j l 'a''t h:i a l');

在操作中查看

如果你碰巧在项目中使用Ouzo Goodies,那么Clock看起来很整洁。

Clock::now()->plusHours(12)->format('F j l 'a''t h:i a l');
echo date('F j l 'a''t h:i a l', strtotime('+12 hours'));

看到它在行动

它的星期几是要求的两倍。不过,不确定你是否真的想要。