2

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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Kelsey
  • 913
  • 3
  • 19
  • 41
  • 1
    Use DateTime objects: `echo (new DateTime('+12 hours'))->format('F j l \a\t g:i a l');` (For a list of available formatting options, have a look at the [documentation for `date()`](http://php.net/date)) – Amal Murali Mar 28 '14 at 19:40

3 Answers3

2

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

Nick Bondarenko
  • 6,211
  • 4
  • 35
  • 56
1

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');
mizmu
  • 111
  • 1
  • 6
0
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.

John Conde
  • 217,595
  • 99
  • 455
  • 496