Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Unix Timestamp to time zone?

I have a unix timestamp that is set to +5, but I'd like to convert it to -5, EST Standard time. I would just make the time stamp be generated in that time zone, but I'm grabbing it from another source which is putting it at +5.

Current Unmodified Timestamp Being Converted Into A Date

<? echo gmdate("F j, Y, g:i a", 1369490592) ?>
like image 596
Necro. Avatar asked May 25 '13 14:05

Necro.


People also ask

Can a UNIX timestamp have a timezone?

Notice that UNIX Epoch is UTC so it identifies without errors a specific moment in time. Never ask about the timezone of a UNIX epoch timestamp, it is UTC by definition.

How do I convert Unix time to normal time?

To easily convert UNIX timestamp to date in the . csv file, do the following: 1. =R2/86400000+DATE(1970,1,1), press Enter key.

Is UNIX timestamp a UTC?

Unix timestamps are always based on UTC (otherwise known as GMT). It is illogical to think of a Unix timestamp as being in any particular time zone. Unix timestamps do not account for leap seconds.

How do I get timestamp from time zone?

You cannot “ get a TimeZone ID from a certain TimeStamp”, that is impossible. Your count-from-epoch was made while accounting for a certain time zone, usually UTC. If must know that intended zone used in creating that count-from-epoch, it cannot be deduced.


1 Answers

Use DateTime and DateTimeZone:

$dt = new DateTime('@1369490592');
$dt->setTimeZone(new DateTimeZone('America/Chicago'));
echo $dt->format('F j, Y, g:i a');
like image 83
John Conde Avatar answered Sep 28 '22 07:09

John Conde