Adjust server time in PHP
in PHP, we can display a date by using date() function..
eg. date("H:i.s");
now, what if for example, your locale is in singapore, and your service is specially for singaporeans (or philippines for filipinos), and your server is in US (hosting)? when you display a date using date() function, it will show the time in US or the time your hosting was using right?
solution: singapore and philippines has the same time zone right? it is GMT+8.. then you can rewrite: date("H:i.s",time()+8);
8 is your timezone.
Adjust server time in PHP
Isn't it also possible to do this?
Like this is an example that you may try.
Code: Select all
<?php
putenv('TZ=Europe/London');
?>
Like this is an example that you may try.
Code: Select all
<?php
echo "Original Time: ". date("h:i:s")."\n";
putenv("TZ=US/Eastern");
echo "New Time: ". date("h:i:s")."\n";
?>
i have wrote a funcion for myself to handle time difference on server and on my country
Code: Select all
$settings["server"]["time"] = "4"; //time differencie from your current time in hours
function showdate($val, $nosec = false, $line_count = "1", $conv=true)
//show time int timestamp, bool hide_seconds, lines number
{
global $settings;
if($conv)
{
if ($val > "946677600")
{
if ($line_count == "1")
{
if ($nosec == false)
return strftime("%Y-%m-%d %H:%M:%S", $val + ($settings["server"]["time"] * 3600));
elseif ($nosec == true)
return strftime("%Y-%m-%d %H:%M", $val + ($settings["server"]["time"] * 3600));
}
else
{
if ($nosec == false)
return strftime("%Y-%m-%d
%H:%M:%S", $val + ($settings["server"]["time"] * 3600));
elseif ($nosec == true)
return strftime("%Y-%m-%d
%H:%M", $val + ($settings["server"]["time"] * 3600));
}
}
else
return "<small>Wrong date code! " . ($val + ($settings["server"]["time"] * 3600)) . "</small>";
}
else
{
return strftime("%Y-%m-%d %H:%M", $val);
}
}
#usage:
$time = showdate(time(), [hide_seconds: true or false], [line_count: 1 or 2], [fix time: true or false ]);
Nice scripts. thanks man.
l Nepali Forum l Seo Company Nepal l Seo Blog l
l Ciggarest Plan l Ciggarest l Ciggarest Program l
l Online Casino l
l Ciggarest Plan l Ciggarest l Ciggarest Program l
l Online Casino l