0

I have the lat and long of a location and want to know whether it is day or night in that location or at least know the time there.

Is there a way to do this without using web services?

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
Adhamox
  • 397
  • 10
  • 19
  • for the user's current location or an arbitrary location? – Michael Dautermann Dec 02 '12 at 20:39
  • 1
    Do you really want to know just whether the sun is up? Because that's a single computation for the whole earth. But the local time is much harder, that changes with politics! – emrys57 Dec 02 '12 at 20:45
  • 1
    @emrys57 is absolutly correct, calculating the tz is a nightmare compared to simple sunset sunrise for location defined by latitude (an dlongitude). You should rename your question – AlexWien Dec 02 '12 at 20:53
  • If you want to actually resolve the correct time zone, rather than just sunrise/sunset, please see [this community wiki entry](http://stackoverflow.com/q/16086962/634824) – Matt Johnson-Pint Apr 18 '13 at 16:16

1 Answers1

3

There is an explanation of how to calculate the time of sunrise and sunset at http://williams.best.vwh.net/sunrise_sunset_algorithm.htm

That produces a result in UTC. The phone knows the current time in UTC. So you can then work out whether the sun has set, and how long ago, at the location you want.

emrys57
  • 6,679
  • 3
  • 39
  • 49