Hi,
My server and where I reside are in different timezones.
How do I set it to be the same as my timezone?
Like adding +10 or something to the time?
How do I go about it?
thanks
| SitePoint Sponsor |





Hi,
My server and where I reside are in different timezones.
How do I set it to be the same as my timezone?
Like adding +10 or something to the time?
How do I go about it?
thanks
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





//Set offset to be the numbe rof hours ahead you want
$offset = "10";
$adj_time = date("g:i:s a", mktime(date("H")+$offset,date("i"),date("s")));
//$adj_time will contain the new time
print $adj_time;
[Edited by freddydoesphp on 10-22-2000 at 12:05 AM]
Please don't PM me with questions.
Use the forums, that is what they are here for.





Hi,
Thanks for helping.
I was also wondering..how do I set the offset for dates?
Since my offset between the server and my timezone is +15, how do i make the dates reflect too?
this is my script version. thanks
<?php
$last_modified = filemtime("$SCRIPT_FILENAME"); print(date("d/m/y", $last_modified));
?>
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





This will show the date reflected by the offset, is that what you are after?
$offset = "15";
$adj_time = date("g:i:s m/d/y", mktime(date("H")+$offset,date("i"),date("s"), date("m"), date("d"), date("y")));
Please don't PM me with questions.
Use the forums, that is what they are here for.





Wow, that's quite cool.Mind if I make use of it?





Actually since one interested me more than normal so I came up with a little function to return a new date and time based on an offset that you set as a parameter. If there are better ways of doing this please someone chime ine, I am alwasy looking for improvement. But here goes:
function adj_timezone($meth, $hour) {
if ($meth == "+") {
$adj_time = date("g:i:s a | m/d/y", mktime(date("H")+ $hour,date("i"),date("s"), date("m"), date("d"), date("y")));
$time = explode("|", $adj_time);
}
elseif($meth == "-") {
$adj_time = date("g:i:s a | m/d/y", mktime(date("H")- $hour,date("i"),date("s"), date("m"), date("d"), date("y")));
$time = explode("|", $adj_time);
}
else {
$time = "";
}
return $time;
}
//Sample Usage: to go back timezones
$time = adj_timezone("-", 10);
//Or to move forward
$time = adj_timezone("+", 10);
//Function returns an array the first element holds the new time the second the new date
$newtime = $time[0];
$newday = $time[1];
print $newtime."<br>";
print $newday."<br>";
Please don't PM me with questions.
Use the forums, that is what they are here for.





Hi,
I'm getting the time and date fom when a file was last modified. So how do i set the offset for it? Using your functions?
thanks for your help..=))
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





<?
function adj_timezone($meth, $hour, $moddate) {
$hour = ($hour * 3600);
if ($meth == "+") {
$newtime = $moddate + $hour;
}
elseif($meth == "-") {
$newtime = $moddate - $hour;
}
else {
$time = "";
}
$adj_time = DATE("m-d-y | g:i:s a", $newtime);
$time = explode("|", $adj_time);
return $time;
}
$moddate = filemtime("./iplister.php");
//To move forward three params(-/+, number of hours, filemtime
$time = adj_timezone("+", 10, $moddate);
//Function returns an array the first element holds the new time the second the new date
$newtime = $time[0];
$newday = $time[1];
print $newtime."<br>";
print $newday."<br>";
?>
Please don't PM me with questions.
Use the forums, that is what they are here for.

You could also do it this way:
$offset can be changed to - or + numbers.Code:<? $offset = '10'; #hours $offset_time = time() + ($offset * 3600); #3600 seconds in one hour $readable_offset_time = date("g:i A",$offset_time); echo $readable_offset_time; ?>





Yeah but what if you wanted to use it more than once on your page, you would have to write that code every time, why not make a function out of it, and then you can call on the function with one line of code whenever you need it?
Please don't PM me with questions.
Use the forums, that is what they are here for.

True. Here is a function for the code
*edit*Code:<? function time_offset($offset) { $offset_time = time() + ($offset * 3600); #3600 seconds in one hour $readable_offset_time[0] = date("g:i A",$offset_time); $readable_offset_time[1] = date("F d, Y g:i A",$offset_time); return $readable_offset_time; } $time = time_offset('-24'); echo $time[1]; #for date and time echo $time[0]; #for just time ?>
included function to display date also if wanted.
[Edited by robp on 10-23-2000 at 12:49 PM]





Okay, well what if they want to subtract hours, your function doesn't allow for that, furthermore the one I posted above allows for this and returns a nice array with the date and the time. Though they pretty much do the same thing
Please don't PM me with questions.
Use the forums, that is what they are here for.

not to get in an argument about who's function is better, but the one I wrote can actually subtract time if the offset is negative.





I used freddy's very first tiny little function and used "-4" and it worked like a charm...





I don't want to argue about something so silly either, but what the guy was looking for who started the post was a way to take the value of filemtime() and add 10 hours to it, so that is what I gave hime, yours is good, but it isn't what he was after.
Please don't PM me with questions.
Use the forums, that is what they are here for.





Hi Guys,
Thanks for your help.
But Hey, there ain't a need to quarrel. Both functions are good in their own ways and I'm keeping both for reference.
robp's would be good for just displaying the time yah? =)
Anyhow,
I'm using freddydoesphp's as it allows more configurations and allow me to set the file last modified too.
Thnaks for your help.
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
Bookmarks