Page 1 of 1

How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 3:46 am
by Homesick
Hi guys

how could I get the date and time of my pc without considering the timezone ,, since date() function rely on the timezone value that is set by date_default_timezone_set(),, but i need just to get the current time of the pc as it appears in the clock without taking care of the timezone

is there any such function ???

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 4:55 am
by dgreenhouse
See: localtime() in the PHP manual.
But the timezone still has an effect.

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 5:00 am
by afr_dnf2011
If it is only the issue of local pc time then it can be done with javascript.

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 5:12 am
by Homesick
thanks dgreenhouse ,, but as u said timezone still has an effect,,

afr_dnf2011,, i need to do it with ONLY PHP :(

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 5:54 am
by afr_dnf2011
If you mean the time on the user's computer, you can't. PHP runs on the server, not on the client. You use Javascript to get the time on the client computer and send it to the server's PHP code. (AJAX would be the easiest way to do it.)

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 6:47 am
by Homesick
nop I meant the time of the server itself,, i just run the code on the server there is no client side.

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 7:31 am
by afr_dnf2011
Then there is no luck in PHP :cry: . May be this function will be available in later version of PHP. You can also try to implement that function :idea: .

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 7:42 am
by Homesick
good idea ;)

thanx for your help :)

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 11:04 am
by John Cartwright
It doesn't make sense that you want a datetime without considering timezones. You can't have a time without a timezone.

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 11:28 am
by afr_dnf2011
@John really your code is awesome & unique :lol:

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 11:36 am
by John Cartwright
afr_dnf2011 wrote:@John really your code is awesome & unique :lol:
Thanks.. I think?

What are you referring to?

Re: How to get the local PC time regardless the timezone

Posted: Sun Mar 27, 2011 2:55 pm
by Weirdan
John Cartwright wrote:What are you referring to?
Signature, I guess.

Re: How to get the local PC time regardless the timezone

Posted: Tue Mar 29, 2011 6:55 am
by Homesick
John Cartwright wrote:It doesn't make sense that you want a datetime without considering timezones. You can't have a time without a timezone.
Hi Jhon,, thx for ur reply

My problem is that the time generated from the date() function was changed since the timezone's "time" has been changed (became 1 hr ahead)

I just want a function that takes the time from the pc clock as it is,,

any ways ,, i solved my issue by changing the timezone to the appropriate timezone that give me the correct date