0

I'm trying to display the date and clock in my col-md-3 with my current timezone (Asia/Makassar) and using 24 hour format.

<?php
    $dateToday = date("D, d M Y H:i:s");
    echo $dateToday;
?>

This is what I expected:

Sat, 2 Jan 2016 10:16:02
JON PANTAU
  • 395
  • 4
  • 14
  • 1
    You forgot quotes around your parameter to date() – John Conde Jan 02 '16 at 02:17
  • Careful. Do you want to display the server's time or the user's time? PHP will display the server's time, which will be "wrong" for the user if they are in a different time zone. – Matthew Herbst Jan 02 '16 at 02:17
  • *"This is what i expected"* - and what is it exactly did you get back? ;-) [Parse error: syntax error, unexpected 'M' (T_STRING)?](http://php.net/manual/en/function.error-reporting.php) - *Yep* – Funk Forty Niner Jan 02 '16 at 02:18
  • So what is your timezone set to in php.ini? – Mark Baker Jan 02 '16 at 02:18
  • When learning PHP, **always** refer to the official manuals on the [PHP.net](http://php.net) website ***first***. http://php.net/manual/en/function.date.php `string date ( string $format [, int $timestamp = time() ] )` http://php.net/manual/en/language.types.string.php – Funk Forty Niner Jan 02 '16 at 02:24
  • yeah but the matter is how to sync my page clock with specific time zone, because it has +12 hours difference – JON PANTAU Jan 02 '16 at 04:17

1 Answers1

1

You must pass a string to the date object:

$dateToday=date("D, d M Y H:i:s");

Also note that PHP will show the date according to the timezone of the server, not the client. You can override this to a different timezone if you would like:

http://php.net/manual/en/function.date-default-timezone-set.php

John Shammas
  • 2,687
  • 1
  • 17
  • 33