So, I'm writing a script that automatically retrieves the user's timezone and then translates all of the dates, however, I seem to be having a problem with DateTime's input string.
It says that it should be able to take in any type of UNIX timestamp (according to the docs; I'm assuming this is what is returned from time() as well), this just isn't the case for me.
public static function displayDate($date, $format = "Y-m-d H:i:s", $time_zone_name = null) {
if($time_zone_name == NULL) {
$time_zone_name = self::fetchTimezone();
}
$new_date = new DateTime($date, new DateTimeZone($time_zone_name));
return $new_date->format($format);
}
public static function fetchTimezone() {
return $time_zone_name = timezone_name_from_abbr('', -$_COOKIE['time_zone_offset']*60, $_COOKIE['time_zone_dst']);
}
Example/Usage:
echo common::displayDate(time());
The problem is that all of the dates I store are saved as results from time() so all of the things are going in are UNIX integer timestamps.
Am I doing this wrong - I'm really lost. Any help would be much appreciated.
Dan