Simulating The Sun In The Sky

This is a discussion on Simulating The Sun In The Sky within the Game Programming forums, part of the General Programming Boards category; Hello,
I'm thinking of perhaps using the system time as a base for implementing real-time daylight in a game, i.e. ...

Simulating The Sun In The Sky

Hello,

I'm thinking of perhaps using the system time as a base for implementing real-time daylight in a game, i.e. if you're playing the game at 10pm it will be dark in game, early afternoon the sun will be out, etc.

To this end, I've knocked up a ridiculously simple Windows-based model, attached. At the moment all it does it get the system time, translate it using the current time zone and use the hour to determine where the sun should be (for now I'm assuming that the sun rises at 6am and sets at 6pm).

Here comes the science bit:- is there a way that I can determine when the sun rises and sets given a time zone? Can I account for those weird places like northern Sweden where they have perpetual darkness/daylight? Would I be able to calculate this or should I instead refer to some sort of Internet database to retrieve the values?