hi12
July 20, 2016, 2:28pm
1
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
rob
July 20, 2016, 3:22pm
2
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 dayPart = "night" elseif hour \< 10 then dayPart = "morning" elseif hour \< 18 then dayPart = "day" else 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
rob
July 20, 2016, 3:22pm
4
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 dayPart = "night" elseif hour \< 10 then dayPart = "morning" elseif hour \< 18 then dayPart = "day" else 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