Hi,
Can anyone help me out .
Req: I have to convert one of my server Date/Time (timezone) which is
in America/Denver to UTC or GMT time zone .
I have tried the below but both gives me same date/time pl help.
<?php
/** Converts a timestamp between arbitrary timezones. */
function tz_to_tz($times tamp,$from_tz,$ to_tz) {
$old_tz = getenv('TZ');
// Parse $timestamp and extract the Unix time.
if(!empty($from _tz))
putenv("TZ=$fro m_tz");
$unix_time = strtotime($time stamp);
// Unix time is seconds since the epoch (in UTC).
// Express the Unix time as a string for timezone $tz.
putenv("TZ=$to_ tz");
$result = strftime("%Y-%m-%d %H:%M %Z",$unix_time) ;
putenv("TZ=$old _tz");
return $result;
}
/** Converts a timestamp with timezone information into
* an arbitrary timezone. */
function to_tz($timestam p_with_timezone ,$to_tz) {
// Set $from_tz to blank, so that $timestamp_with _timezone
// is parsed to determine timezone.
return tz_to_tz($times tamp_with_timez one,'',$to_tz);
}
/** Converts a timestamp with timezone information into UTC. */
function to_utc($timesta mp_with_timezon e) {
return to_tz($timestam p_with_timezone ,'UTC');
}
$now = date("Y-m-d H:i");
$utc_time = tz_to_tz($now," America/Denver","UTC");
echo "Local time is ::".date("Y-m-d H:i")."<br>";
echo "UTC Time is ::".$utc_time ;
?>
Can anyone help me out .
Req: I have to convert one of my server Date/Time (timezone) which is
in America/Denver to UTC or GMT time zone .
I have tried the below but both gives me same date/time pl help.
<?php
/** Converts a timestamp between arbitrary timezones. */
function tz_to_tz($times tamp,$from_tz,$ to_tz) {
$old_tz = getenv('TZ');
// Parse $timestamp and extract the Unix time.
if(!empty($from _tz))
putenv("TZ=$fro m_tz");
$unix_time = strtotime($time stamp);
// Unix time is seconds since the epoch (in UTC).
// Express the Unix time as a string for timezone $tz.
putenv("TZ=$to_ tz");
$result = strftime("%Y-%m-%d %H:%M %Z",$unix_time) ;
putenv("TZ=$old _tz");
return $result;
}
/** Converts a timestamp with timezone information into
* an arbitrary timezone. */
function to_tz($timestam p_with_timezone ,$to_tz) {
// Set $from_tz to blank, so that $timestamp_with _timezone
// is parsed to determine timezone.
return tz_to_tz($times tamp_with_timez one,'',$to_tz);
}
/** Converts a timestamp with timezone information into UTC. */
function to_utc($timesta mp_with_timezon e) {
return to_tz($timestam p_with_timezone ,'UTC');
}
$now = date("Y-m-d H:i");
$utc_time = tz_to_tz($now," America/Denver","UTC");
echo "Local time is ::".date("Y-m-d H:i")."<br>";
echo "UTC Time is ::".$utc_time ;
?>
Comment