Hi Everybody ,i have a problem with DateTime class,I am using DateTime class in my program it works fine in php 5.2.6 .but the version in my server is php 5.1.6 so is there any class to replace the same functionality.please check the code below and if u find any solution for this please reply me.

CODE:
--------------------------------------------------------------------------------------------------------

function trackCountry($ip,$date)
{
include("geoip.inc");
include("geoipcity.inc");
include("geoipregionvars.php");
//function for opening the database 
$gi = geoip_open("/opt/lampp/htdocs/theopencamp/Ver2/theopencamp2/include/GeoLiteCity.dat", GEOIP_STANDARD);
//function to retrieve the information of the particular ip and casting it to array
$rsGeoData =(array) geoip_record_by_addr($gi,$ip);
geoip_close($gi);
         if(is_array($rsGeoData))
             {
               $countrycode=$rsGeoData['country_code'];
               $region=$rsGeoData['region'];
             }
             //Converting of localtime to utc
require("timezone.php");
$tz= get_time_zone($countrycode,$region);
$timestamp = 1240349566;
 // set this to the time zone provided by the user
 // create the DateTimeZone object for later
$dtzone = new DateTimeZone($tz);
 // first convert the timestamp into a string representing the local time
$time = date('r', $timestamp);
 // now create the DateTime object for this time
$dtime = new DateTime($date);
 // convert this to the user's timezone using the DateTimeZone object
$dtime->setTimeZone($dtzone);
// print the time using your preferred format
$time = $dtime->format('Y-m-d-H-i-s');
return $time;
}
?>

Recommended Answers

All 7 Replies

Member Avatar for diafol

which part is causing the problem? Isolate the steps and echo or print out the variables. You need to know which elements are causing problems before you start making wholesale changes.

which part is causing the problem? Isolate the steps and echo or print out the variables. You need to know which elements are causing problems before you start making wholesale changes.

the DateTime function is throwing an error

$dtzone = new DateTimeZone($tz); is throwing error and this class does'nt support in php5.1.6 version so is there any replacement for that class

What is the error?

Member Avatar for diafol

are you just trying to 'correct' a server datetime to the user's local time?

Are you getting any error or incorrect date?
if it is incorrect date then setting the default timezone as below will solve ur problem

date_default_timezone_set('Asia/Calcutta');

Also paste the code for "timezone.php"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.