Get device time of day (morning, day, evening, night)

Hi all,

I was wondering if it was possible to get the device time, and figure out what time of day it is (morning, day, evening, night). I would like to have my app adapt a bit based on the player’s time (darker scene at night, brighter scene during the morning), and was wondering how I could capture the devices time to adapt these variables.

Thanks

Look at the os.date() API call:  https://docs.coronalabs.com/api/library/os/date.html

You could do something like:

local hour = os.date("%H") local dayPart if hour \< 5 or hour \> 21 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "night" elseif hour \< 10 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "morning" elseif hour \< 18 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "day" else &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "evening" end

or something like that (whatever hours you use to determine what part of the day it is…

Thier is also a free rest api for sunrise and sunset
http://sunrise-sunset.org/api

Look at the os.date() API call:  https://docs.coronalabs.com/api/library/os/date.html

You could do something like:

local hour = os.date("%H") local dayPart if hour \< 5 or hour \> 21 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "night" elseif hour \< 10 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "morning" elseif hour \< 18 then &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "day" else &nbsp;&nbsp;&nbsp;&nbsp; dayPart = "evening" end

or something like that (whatever hours you use to determine what part of the day it is…

Thier is also a free rest api for sunrise and sunset
http://sunrise-sunset.org/api