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.
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:18answered 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
Ram Sharma
8,5367 gold badges44 silver badges55 bronze badges
answered Mar 13, 2014 at 23:20
1
//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.
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