0

I need my local timezone name like America/Chicago ?

I have written my code like this

$date = new DateTime();
$timeZone = $date->getTimezone();
echo $timeZone->getName();

But I am getting UTC as output but I don't need this. I need the timeZone name. How can I get it ?

DigitalDrifter
  • 15,855
  • 3
  • 35
  • 47
Shakil Anwar
  • 111
  • 8
  • When you say *your* local time zone, do you you mean the time zone on the server? Or the time zone in your browser? (The latter is a JavaScript thing, not a PHP thing.) – Matt Johnson-Pint Apr 10 '20 at 17:26

1 Answers1

1

You are probably getting the timezone set in the server, that's the best you can get. If you want America/Chicago you will need to configure that in the server.

You could also specify the timezone you want to work with when instantiating a new DateTime object, but since the server is probably set as UTC, you need to be careful and juggle the conversion. For instance:

 $dt = new DateTime('2014-06-22 11:10:58', new DateTimeZone('UTC'));
 $dt->setTimezone(new DateTimeZone("Europe/Paris"));
 $dateString = $dt->format('Y-m-d h:i:s');
fromvega
  • 3,478
  • 4
  • 30
  • 41