Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kevindosi

macrumors regular
Original poster
Mar 16, 2006
191
0
I don't know if this is possible, and I don't know if this is the best place to ask it, but I figured that if it's possible then someone here would know how to do it.
I'm using a plugin on wordpress to show my current location on my webpage with text (ie. "I'm currently in Houston, TX." I'd like to also put the current local time on my webpage automatically, so it'll say something like "I'm in Houston, TX and it's 5:00pm" Does anyone know if this is possible?
 
Thanks for the reply,
This looks fine, but I'm looking for something that will update automatically based on my current location according to google latitude. From what I can tell, this script can't do that. Is there any other way?
 
Hey thanks for your response,
I'm a little confused by this How could this be used to automatically update the local time based on my current location?
 
Let me unconfuse you.

Visit this site to demo and possibly purchase their DB15 product which is a powerful and easy to use database that returns a lot of information about a user using geo-location techniques.

http://www.ip2location.com/

For example, I simply visited the site and it reported all this about me:

Location :
US.gif
UNITED STATES, DISTRICT OF COLUMBIA, WASHINGTON Latitude / Longitude : 38.9048 LATITUDE, -77.0354 LONGITUDE Connecting through : U.S. DEPT. OF COMMERCE - ITA Time Zone : UTC -04:00 Net Speed : DSL IDD Code : 1 Area Code : 202 Weather Station : USDC0001 - WASHINGTON

As you can see, the database fields include longitude and latitude and time zone offset. You can either query based on IP as it did for me, or contact their helpdesk or read their documentation and see if you can run your own query passing the latitude/longtitude if you have that information already to get the time zone offset. Once you have that, you calculate local time by adding or subtracting the time zone offset from current GMT time.

Example: GMT -4:00 means the current GMT time minus 4 hours, i.e. if GMT is 8pm, my local time is 4pm. It's up to you to query the database properly and calculate the time using whatever server side language you use. In PHP you'd work with gmdate and gmmktime functions.

-jim
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.