How to get the local PC time regardless the timezone

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

How to get the local PC time regardless the timezone

Post 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 ???
dgreenhouse
Forum Newbie
Posts: 20
Joined: Tue Mar 10, 2009 5:13 am

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

Post by dgreenhouse »

See: localtime() in the PHP manual.
But the timezone still has an effect.
User avatar
afr_dnf2011
Forum Newbie
Posts: 14
Joined: Mon Mar 21, 2011 8:20 pm

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

Post by afr_dnf2011 »

If it is only the issue of local pc time then it can be done with javascript.
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

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

Post by Homesick »

thanks dgreenhouse ,, but as u said timezone still has an effect,,

afr_dnf2011,, i need to do it with ONLY PHP :(
User avatar
afr_dnf2011
Forum Newbie
Posts: 14
Joined: Mon Mar 21, 2011 8:20 pm

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

Post 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.)
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

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

Post by Homesick »

nop I meant the time of the server itself,, i just run the code on the server there is no client side.
User avatar
afr_dnf2011
Forum Newbie
Posts: 14
Joined: Mon Mar 21, 2011 8:20 pm

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

Post 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: .
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

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

Post by Homesick »

good idea ;)

thanx for your help :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post 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.
User avatar
afr_dnf2011
Forum Newbie
Posts: 14
Joined: Mon Mar 21, 2011 8:20 pm

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

Post by afr_dnf2011 »

@John really your code is awesome & unique :lol:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post by John Cartwright »

afr_dnf2011 wrote:@John really your code is awesome & unique :lol:
Thanks.. I think?

What are you referring to?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post by Weirdan »

John Cartwright wrote:What are you referring to?
Signature, I guess.
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

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

Post 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
Post Reply