Create a date/time table for local notifications

Hi,

I’m trying to set local notifications at specific times but I can’t find a way to pass in the desired time. Say for example I want to set the notification for 10pm on the 17th of January 2015 how do I create that variable?

[lua]

local futureUtcTime = ???

local secondsFromNow = os.difftime( os.time(), os.time( futureUtcTime ) )

local notificationID = system.scheduleNotification( secondsFromNow, options )

[/lua]

Can I create a table like this:

[lua]

local futureUtcTime = {

                                   hour = 22,

                                   minute = 0,

                                   date = 17,

                                   month = January,

                                   year = 2015

}

[/lua]

Corona made a great tutorial about dates, I would start there if you have not already: http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Thanks for the reply. I did read that but it only seems to help with breaking a date/time down into components. I have the components(entered by the user) as separate variables and I need to compile them into a date table.

I think this should work ok, I changed “januar” into the number 1:

[lua]local futureUtcTime = {

   hour = 22,

   minute = 0,

   date = 17,

   month = 1,

       year = 2015

}

local timestamp = os.time({

  year=futureUtcTime.year,   

  month=futureUtcTime.month, 

  day=futureUtcTime.date, 

  hour=futureUtcTime.hour, 

  min=futureUtcTime.minute, 

  sec=0

})

local secondsFromNow = timestamp - os.time()

print(secondsFromNow)[/lua]

Also if you change “date” into “day” and month into number you could just pass the futureUtcTime table straight into os.time()

That worked perfectly. Thank you very much.

Corona made a great tutorial about dates, I would start there if you have not already: http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Thanks for the reply. I did read that but it only seems to help with breaking a date/time down into components. I have the components(entered by the user) as separate variables and I need to compile them into a date table.

I think this should work ok, I changed “januar” into the number 1:

[lua]local futureUtcTime = {

   hour = 22,

   minute = 0,

   date = 17,

   month = 1,

       year = 2015

}

local timestamp = os.time({

  year=futureUtcTime.year,   

  month=futureUtcTime.month, 

  day=futureUtcTime.date, 

  hour=futureUtcTime.hour, 

  min=futureUtcTime.minute, 

  sec=0

})

local secondsFromNow = timestamp - os.time()

print(secondsFromNow)[/lua]

Also if you change “date” into “day” and month into number you could just pass the futureUtcTime table straight into os.time()

That worked perfectly. Thank you very much.