Pregunta

I am looking for help with my PHP code:

$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)); 

Currently this outputs:

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

I am trying to make this display the current month, day of the month, and the current time plus twelve hours. For example, the output would be:

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

If anyone can help it will be greatly appreciated. Thank you for any help.

¿Fue útil?

Solución

In OOP style:

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

Or just with DateTime:

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

See it in action

Otros consejos

If you happen to use Ouzo Goodies in your project then Clock looks neat.

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'));

See it in action

It has the day of the week twice as requested. Not sure if you really want that, though.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top