FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


converting time into correct timezone?





ChrisCh
Hey, I'm trying to convert time ('seconds since epoch' format) into a readable time in the correct timezone.

For example, I'd like to convert 1164764597 to a readable output such as "24 Nov 2006 08:15 am" (I know that the times aren't the same but you know what I mean:) )

I'd also like the output to be in my timezone (GMT +10 - never with daylight saving) but I don't know how to do it Smile

Any help would be appreciated - even if you can only convert it into a readable time without changing timezone Smile
jabapyth
Easy!
Code:

function DateConvert($myDate){
$h = 10; // GMT+10
$dst = "true"; // CHANGE THIS to false if you dont want dst

if ($dst) {
   $daylight_saving = date('I',myDate);
   if ($daylight_saving){
       $h=$h+1;
   }
}
$hm = $h * 60;
$ms = $hm * 60;
$timestamp = time()+($ms);
$gmdate = gmdate("d F Y g:i a", $timestamp);
return $gmdate;
}
currentDate=DateConvert(time());
echo "Your current time now is :  $currentDate . ";


Good Luck!
ChrisCh
Thanks for your help! I've got it showing the current date, but what I was trying to do is convert a time (in epoch seconds) called from a database into real time Smile I've tried changing the script to accomodate for this but it's not working... It's calling the epoch time from the database correctly, but it's not converting properly! Here's what I've tried changing the code to:

Code:
function DateConvert($myDate){
$h = 10; // GMT+10
$dst = "true"; // CHANGE THIS to false if you dont want dst

if ($dst) {
   $daylight_saving = date('I', $myDate);
   if ($daylight_saving){
       $h=$h+1;
   }
}
$hm = $h * 60;
$ms = $hm * 60;
$timestamp = $result721['time']+($ms);
$gmdate = gmdate("d F Y g:i a", $timestamp);
return $gmdate;
}

$currentDate = DateConvert($gmdate);
echo $currentDate;

I've changed the time() things to variables because it's not the current time I'm after, but it's not working... (also if your wondering, $result721['time'] contains the time that I'm trying to convert) Smile

It's showing "01 January 1970 10:00 am" instead of the time it's supposed to... Does anyone know how to fix this? Smile
Related topics
Microsoft plans to build more Unix features into future vers
Need comments for my site
Support Danish
[php/SQL] Help needed
Possible to change the timezone? (server 2)
A debate of religion, science, and more
converting not bootable iso to bootable CD
Skin Regeneration
Problem with FTP
converting avi to vcd or kvcd
Smart Pricing
Layout Contest ~~~200FRIH for winner + more benifits~~~
related to points
What is fire
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.