4
$\begingroup$

There does not seem to be a direct way to extract the time zone for a ZIP code. Currently, I am first mapping the ZIP code to the states, and then getting the time zones for those states.

"94402" //
Entity["ZIPCode", #] & //
EntityValue[#, "USStates"] & //
Map[EntityValue[#, "TimeZones"] &]

But this is obviously wrong. This will return multiple time zones even when a given ZIP code lies within a single time zone.

Is there a better way of getting the time zone for a ZIP code through Entity?

$\endgroup$
9
$\begingroup$
TimeZoneOffset[Entity["ZIPCode", "94402"]]

-8.

$\endgroup$
  • 1
    $\begingroup$ Ah, didn't occur to me that I don't need to wrap the entity in GeoPosition. Ah well. Graceful method :) $\endgroup$ – Carl Lange Jan 11 at 0:44
  • $\begingroup$ Thank you @CarlLange. $\endgroup$ – kglr Jan 11 at 1:23
6
$\begingroup$

This will do what you want:

TimeZoneOffset[GeoPosition[Entity["ZIPCode", "94402"]["Coordinates"]]]

-8

Each zip code entity has coordinates associated with them, and TimeZoneOffset can take a GeoPosition and return the timezone offset from GMT.

It should be noted that kglr's answer is the shorter (and more graceful) form of this answer - they are doing the same thing under the hood.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.