43372

How to get the time of a given city?

I know that I can display time for a particular location using only JavaScript (and no web service or external data source), but... I want to avoid using this solution because I don't want to have to account for daylight savings time, and any other factors that make it complicated.

I'm looking for an easier way to display the time and always for a particular city (or zip code, or whatever identifier works...).

For example, I want a page to always say:

<strong>The current time in Miami is "X"</strong>

(where "X" should be replaced by the current time in Miami)

Is there a web service (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?

Answer1:

Is there a web service (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?

I don't know of a single web service that will do the job.

Google's Geocoding API can help. You can feed it a parameter, and it will return certain information, such as the latitude/longitude. Example using a zip code, but I'm sure you can easily put in a city/state pair and make it work.

You can then take that lat/long pair and point it at service like GeoNames. They have a timezone API that takes a lat/long pair and returns quite a bit of information. Example using the lat/long from the zip code.

Recommend

  • Getting last price from specific product on MYSQL (faster than this)
  • UiTabController app setup
  • split working for-loop calling JSON in 2 parts with jquery/javascript
  • I keep getting java.io.NotSerializableException: java.io.ObjectOutputStream
  • Adding list of data in Firebase
  • How should I store date/time objects in SQL?
  • Left Join ON LIKE needs something like LIMIT
  • Facebook Events and timezones, how to convert UTC datetime to what facebook expects?
  • Apache Spark: How to structure code of a Spark Application (especially when using Broadcasts)
  • Necessary to pin_ptr on C++ CLR Value types, why?
  • Embed multiple jpeg images into EXCEL programmatically?
  • JPA - getting distinct value from one column
  • Removing levels from data frame read from CSV file - R
  • php regex remove digits
  • Add delivery info to query in SAP Crystal Reports
  • Exception handling as per java coding standards
  • DOMXML, PHP4 => PHP5
  • Update a record where _id = :id with Mongoose
  • Can I call custom javascript from an R jupyter notebook
  • textIndicatorPrecision in dojox.dgauges using dojo
  • Whats the right place for testhelper-classes? (phpunit/best practise)
  • How to select table rows/complete table?
  • CoreData basics – to-many relationship array data
  • Eloquent Relationship on Partial Match
  • What is the reason that Policy.getPolicy() is considered as it will retain a static reference to the
  • SQL query to group by maximal sets of a column having inner consecutive distances below a threshold
  • Want to understand iframe breakout code
  • Get used tables from sql query [duplicate]
  • XMLBeans Duplicate Class and Class Not Found Errors
  • R Split data.frame using a column that represents and on/off switch
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Invalid access key error using credentials redeemed from an amazon open id token
  • PHP: When would you need the self:: keyword?
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • reshape alternating columns in less time and using less memory
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?