World Time Engine provides all kind of time related information for any given place on this planet. You can use their free web portal and enter GPS coordinates, city names or postal codes and retrieve timezone, daylight saving and more. Otherwise they provide an API to get the data via an http GET request. This service is not free, they charge you a 14 U$ for 50.000 requests.
API details you find here, but in short:
- http://worldtimeengine.com/api/<apikey>/<latitude>/<longitude>
and you get something like this:
- <?xml version="1.0" encoding="UTF-8" ?>
- <timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="http://worldtimeengine.com/timezone.xsd">
- <version>1.1</version>
- <location>
- <region>Australia/New South Wales</region>
- <latitude>-33.8671</latitude>
- <longitude>151.207</longitude>
- </location>
- <time>
- <utc>2008-02-13 00:50:30</utc>
- <local>2008-02-13 11:50:30</local>
- <zone>
- <hasDST>true</hasDST>
- <current>
- <abbreviation>EDT</abbreviation>
- <description>Eastern Australia Daylight Savings Time</description>
- <utcoffset>+11:00</utcoffset>
- <isdst>true</isdst>
- <effectiveUntil>2008-03-29 19:00:00</effectiveUntil>
- </current>
- <next>
- <abbreviation>EST</abbreviation>
- <description>Eastern Australia Standard Time</description>
- <utcoffset>+10:00</utcoffset>
- <isdst>false</isdst>
- <effectiveUntil>2008-10-25 18:00:00</effectiveUntil>
- </next>
- </zone>
- </time>
- </timezone>
How can we use Groovy to request for the data and access its detail ?
- Get yourself a API Key from world time engine
- We use the Groovy Console (groovyConsole from the shell)
- We need the httpbuilder library
- Copy http-builder-0.5.0.jar and all dependencies into the ./groovy/lib folder in your home folder
- Execute this code:
- import groovyx.net.http.*
- import static groovyx.net.http.ContentType.*
- def worldTime = new RESTClient("http://worldtimeengine.com/api/{yourkey}/35.7647018432617/140.386001586914")
- def resp = worldTime.get( contentType : XML)
- println resp.data.time.zone.current.abbreviation.text()
- println resp.data
- You see it is fairly simple to access specific fields with the groovy notation resp.data.time.zone.current.abbreviation.text()
How do I use this ?
- I use Groovy classes in my java EE application. You can cut down on boilperplate code dramatically by using Groovy !
- The above service I use in an location aware application.







