【问题标题】:Convert basic time chosen into date table for Corona local notifications将选择的基本时间转换为 Corona 本地通知的日期表
【发布时间】:2012-07-17 00:44:30
【问题描述】:

希望在用户在我的 Corona 应用中设置的特定时间设置本地通知。我有基本的通知工作,使用以下指南: http://developer.coronalabs.com/reference/index/systemschedulenotification

local utcTime = os.date( "!*t", os.time() + 60 )
local notification = system.scheduleNotification( utcTime, options )

但我想利用用户选择的时间,构建一个以coordinatedUniversalTime 格式的日期表,来代替上面代码的os.time() + 60 部分。有人知道怎么做吗?

我的时间选择器返回一个基本的小时和分钟值,以及它是上午还是下午。

谢谢!

【问题讨论】:

标签: lua coronasdk


【解决方案1】:

好的,明白了,很简单。

local options = {
           alert = "Alert Text",
           sound = "audio/sound.caf"
        }

        local currentDate = os.date( "*t" )
        local notificationHr
        if reminderPicker1.getAMPM() == "am" then
            notificationHr = reminderPicker1.getHour()
        else
            notificationHr = reminderPicker1.getHour() + 12
        end
        local utcTime = os.date( "!*t", os.time{year=currentDate.year, month=currentDate.month, day=currentDate.day, hour=notificationHr, min=reminderPicker1.getMin(), sec=0 } )
        local notification = system.scheduleNotification( utcTime, options )

【讨论】:

  • 您应该接受自己的答案,因为它解决了您的问题。这将改善 SO 知识库。
  • 这对我有帮助。但我在这里得到了更多帮助:forums.coronalabs.com/topic/… 并且要小心这段代码,因为 12 是一个特殊的例外。如果您将 12 点添加到 12PM,您将在 24 点,这实际上是午夜。如果您离开 12AM 而不添加 12,您将停留在 12 点,这实际上是中午。
猜你喜欢
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
  • 2018-08-30
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 2018-08-21
  • 2018-07-15
相关资源
最近更新 更多