Saturday, February 28, 2009

Re: how to set current time for local computer

I had the same issue a week a go, my server is located on GMT -6 and
my country is on GMT -5
The function takes the GMT from Server within the timestamp

/* @param integer $time server timestamp (time()) or whatever
timestamp
* @param integer $userGMT this is the GMT you want convert to
* @return timestamp calculated
*/

//I put this function on app_controller
function gmtConvert($time, $userGMT) {
//Gets server GMT (-5, -4 0, 5, 6 etc.)
$serverGMT = ((int)date('O', $time))/100;
//Calculates the difference between server and user's GMT
$difference = $userGMT - $serverGMT;
//Calculates the new timestamp
$newtime = $time + ($difference * (60 * 60));
return $newtime;
}

//This is how to use
//gmtConvert(server timestamp, your GMT);
$this->gmtConvert(time(), -5);

Hope this help!

On Feb 28, 9:53 am, vikas <vikas...@gmail.com> wrote:
> Hello all..
>
> My problem is my site is running on a server resides on different
> country..
>
> I used to show the current time on a home page.. but It shows me
> server time..which is nearly 12 hours behind my country..
>
> I want to show user a time of a computer he or she uses..
>
> P.S. : I used date() function..to show date and time
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: