-1

I need to set timezone in my laravel project but it's not giving exact same time. There is a difference in current time (checking via google) and the time my code is showing. My code is below:

date_default_timezone_set($generalSettings[0]->timeZone);
// $generalSettings[0]->timeZone = "America/Denver"
echo date("Y-m-d h:m:s");
exit;

It's showing "2016-12-21 01:12:05" while current time in "Time in Denver, CO, USA" 1:40 A.M. What I'm missing here that should display exactly same date time. Thanks!

ÛmÄîr MÄlîk
  • 453
  • 2
  • 10
  • 23

3 Answers3

0

You have to set your default timezone php function, so if yours is Denver you have something like :

date_default_timezone_set('America/Denver');
$date = date('m/d/Y h:i:s a', time());
echo $date;

Hope it helps you, anyway check it out :

Here

Edit : If you want it on server have to work on : php.ini

Community
  • 1
  • 1
Teshtek
  • 1,212
  • 1
  • 12
  • 20
-1

You should change Time Zone on yours server.

brtsos
  • 373
  • 3
  • 14
  • I've to set dynamically as this field is set by users according to their timezones, How can I set timezone of server via program? – ÛmÄîr MÄlîk Dec 21 '16 at 08:57
  • Solution given by @teshtek worked for me as I don't want to play with the server time by changing it otherwise your answer was also correct. Thanks for your time and help. – ÛmÄîr MÄlîk Dec 21 '16 at 09:08
-1

Is the timezone of your system correctly set? If yes, try to set it again or use an other NTP server

How to set timezone with Linux (tried on Ubuntu Server):

dpkg-reconfigure tzdata
EmotionalSnow
  • 49
  • 3
  • 7
  • Can't I do this without interfering in server settings by just using PHP code? This filed will be set by users according to their timezones and I think if I set timezone of server it will effect time of other users too. – ÛmÄîr MÄlîk Dec 21 '16 at 09:00
  • @ÛmÄîrMÄlîk do you want the users to be able to set their own timezone? – EmotionalSnow Dec 21 '16 at 13:15