I have a timestamp the user enters in GMT.
I would then like to display that timestamp in gmt, cet, pst, est.
Thanks to the post below I have made, which works perfectly!
public static function make_timezone_list($timestamp, $output='Y-m-d H:i:s P') {
$return = array();
$date = new DateTime(date("Y-m-d H:i:s", $timestamp));
$timezones = array(
'GMT' => 'GMT',
'CET' => 'CET',
'EST' => 'EST',
'PST' => 'PST'
);
foreach ($timezones as $timezone => $code) {
$date->setTimezone(new DateTimeZone($code));
$return[$timezone] = $date->format($output);
}
return $return;
}
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.
The UNIX timestamp is the number of seconds (or milliseconds) elapsed since an absolute point in time, midnight of Jan 1 1970 in UTC time. (UTC is Greenwich Mean Time without Daylight Savings time adjustments.) Regardless of your time zone, the UNIX timestamp represents a moment that is the same everywhere.
=(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number). For other time zones: =((A1 +/- time zone adjustment) / 86400) + 25569.
For timestamp with time zone , the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT ).
You could use PHp 5's DateTime
class. It allows very fine-grained control over Timezone settings and output. Remixed from the manual:
$timestamp = .......;
$date = new DateTime("@".$timestamp); // will snap to UTC because of the
// "@timezone" syntax
echo $date->format('Y-m-d H:i:sP') . "<br>"; // UTC time
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "<br>"; // Pacific time
$date->setTimezone(new DateTimeZone('Europe/Berlin'));
echo $date->format('Y-m-d H:i:sP') . "<br>"; // Berlin time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With