Current Time

Hi all, I’m just starting out with Corona and have a quick question.

I’m trying to get the current os time into a variable - so that if the time is between two points (say 9am and 11am), I can use it to create an event.

Could someone shine a bit of lit on the time element? I don’t completely understand why I only get the time as milliseconds etc.

Thanks in advance
Steve

[import]uid: 45932 topic_id: 8065 reply_id: 308065[/import]

You mean this ?

local date = os.date("*t")
if (date.hour >= 21) and (date.min >= 30) then
end
[import]uid: 13125 topic_id: 8065 reply_id: 28919[/import]

Thanks for your help djung7.

I’ll give this a go tonight and let you know (on an old Mac with 10.4 at the moment so can’t do anything!) [import]uid: 45932 topic_id: 8065 reply_id: 28956[/import]

Hi, this is the stripped-down code I’ve got so far. I still don’t quite know what needs to happen to get the hours to work…

  
local time\_now = os.time('\*t');  
  
function timeTest()  
 if (time\_now \>= ...) and (time\_now \< ...) then  
 display.newImage("good\_night.png",0,0)  
 else  
 display.newImage("good\_day.png",0,0)  
 end  
end  
  
timeTest()  
  

Any help would be very gratefully received!

Thanks
Steve [import]uid: 45932 topic_id: 8065 reply_id: 29056[/import]

The API should help: http://developer.anscamobile.com/reference/index/osdate [import]uid: 42078 topic_id: 8065 reply_id: 29061[/import]

Thanks sidasa. So I need to use os.date not os.time? That’s why it wouldn’t work then?

Still quite new to this, but’s making more sense now.

Thanks again. [import]uid: 45932 topic_id: 8065 reply_id: 29064[/import]