Est time zone in php

I want to get current time of US/Eastern timezone. How would I achieve that.

I have tried following code but it is displaying my system's time.

<?php
   date_default_timezone_set('US/Eastern');
   $currenttime = date('h:i:s:u');
   list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);
   //print "&time2=".$secs."&time1=".$mins."&time0=".$hrs;
?>

I am using this script with flash so commented out 'print' line.

Est time zone in php

halfer

19.6k17 gold badges92 silver badges175 bronze badges

asked Dec 16, 2010 at 0:34

2

<?php
   echo date_default_timezone_get();
   $currenttime = date('h:i:s:u');
   list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);
   echo " => $hrs:$mins:$secs\n";

   date_default_timezone_set('US/Eastern');
   echo date_default_timezone_get();
   $currenttime = date('h:i:s:u');
   list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);
   echo " => $hrs:$mins:$secs\n";

   date_default_timezone_set('America/New_York');
   echo date_default_timezone_get();
   $currenttime = date('h:i:s:u');
   list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);
   echo " => $hrs:$mins:$secs\n";

?>

Seems to work here (in Berlin):

Europe/Berlin => 01:42:42
US/Eastern => 07:45:18
America/New_York => 07:45:18

answered Dec 16, 2010 at 0:44

mikumiku

175k46 gold badges303 silver badges307 bronze badges

3

$amNY = new DateTime('America/New_York');
$estTime = $amNY->format('h:i:s:u');

or if you are using php 5.4 and above

estTime = (new DateTime('America/New_York'))->format('h:i:s:u');

date_default_timezone_set() will affect the whole script and should be used carefully

Est time zone in php

Ram Sharma

8,5367 gold badges44 silver badges55 bronze badges

answered Mar 13, 2014 at 23:20

Est time zone in php

1

http://www.php.net/manual/en/timezones.php

Looks like the US/Eastern is deprecated. Try America/New_York

EDIT this probably won't fix your problem, but you should do it anyway. Being deprecated means that they could remove it in the future.

answered Dec 16, 2010 at 0:44

RobertRobert

6,3242 gold badges23 silver badges25 bronze badges

The easiest way is probably to use gmmktime() to get the Unix timestamp for the current GMT, then subtract 5 hours from it. That way you get Eastern Time no matter where the server happens to be.

Est time zone in php

Saty

22.3k7 gold badges30 silver badges49 bronze badges

answered Dec 16, 2010 at 0:45

2

I just use

<?php
Date_default_timezone('est');
$lv=date('l, F jS, Y, g:I:s A T,$ir['laston']);
?>
<b>last visit</b> <em>$lv.</em>

Seems to work perfectly for me on my game that I'm working on. Mind you if you want to use it just remove the $ir['laston'] and it should work no problem

answered Nov 30, 2017 at 10:55

2

What is PHP time zone?

The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts.

Where is PHP timezone set?

8 Answers.
Go to your phpinfo() page and search for Loaded Configuration File and open the php. ini file mentioned under that section..
Change the default timezone settings by adding your new timezone by modifying this line: date. timezone=Asia/Kolkata ..
Save the php. ... .
Restart the Apache server..

How can I modify the PHP timezone setting for my website?

Open Hosting → Manage → PHP Configuration page. There, open the PHP options tab and edit the date. timezone value: If you are not sure which time zone to insert, check the Time Zone Map.

How do I set default timezone?

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.