Jump to content

Local computer time


icekat83

Recommended Posts

Hey,

 

I'm trying to code a page which is supposed to bring up the time of a person's computer. Is this possible without majorly complicated coding? I'm good with GMT offsets and stuff but I don't know how to get the time of a person's computer. I don't want other stuff, just the time so I can edit the time based on where they are.

 

I don't know if I'm making sense so here's an example...

 

If someone does a forum post at 2pm Sydney time but it's 5pm Perth time. How can I make it so that someone in Perth sees 5pm but someone in Sydney sees 2pm...without them manually telling me their timezone?  :shrug:

 

I read about using IP addresses but don't know much (Ok anything) about this , any hints or good sites to view would be appreciated? Or the answer if it's not too complex.  :shy:

 

Preferably I'd like to get the time in the 11 digit "time()" format so I can use it in tables and translate it with an existing function.

 

IceKat

Link to comment
https://forums.phpfreaks.com/topic/214691-local-computer-time/
Share on other sites

You could use javascript to easily get the users time, and store it as $_SESSION['time']. As long as you don't have a problem with users being able to change their time... or if their time is incorrect then their true location wouldn't match your function's location for them.

 

Link to comment
https://forums.phpfreaks.com/topic/214691-local-computer-time/#findComment-1117029
Share on other sites

Yes but JavaScript can be disabled. How do website statistics robots (like google analytics) do it? They get location and stuff which is basically what I need.

 

I don't want to invade privacy or anything, just be able to automatically alter times for web viewers.

Link to comment
https://forums.phpfreaks.com/topic/214691-local-computer-time/#findComment-1117034
Share on other sites

Better yet,

<noscript><?php echo "Server Time: ".date(format); ?></noscript>

 

Edit, I have to admit I haven't been fair to you. You mentioned google analytics, which made me think duh -> ip -> trace - > timezone.

 

$region = geoip_region_by_name($_SERVER['REMOTE_ADDR']);
$zone = geoip_time_zone_by_country_and_region($region['country_code'],$region['region']);

 

However this method is not as accurate as you'd like, with javascript->ajax->php more accurate, and being the most accurate: asking the user.

Link to comment
https://forums.phpfreaks.com/topic/214691-local-computer-time/#findComment-1117040
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.