【问题标题】:Make a count down timer from an Int input? [closed]从 Int 输入做一个倒数计时器? [关闭]
【发布时间】:2016-12-20 15:27:12
【问题描述】:

所以我希望用户能够输入未来的天数(Int),然后单击按钮开始倒计时。我希望输出是日期之前的 Int。感谢您的帮助。

【问题讨论】:

    标签: ios swift xcode time nsdate


    【解决方案1】:

    我假设您在n 天之后有日期,我称之为dateAfterNDays,因此解决方案将使用NSDateComponents

    components(_:fromDate:toDate:options:)
    

    方法并使用.Day 组件查找差异。示例如下:

    let dateDifference = NSCalendar.currentCalendar()
                                   .components(.Day,
                                               fromDate: today,    // currentDate
                                               toDate: dateAfterNDays!,    // date for countdown
                                               options: [])
    
    let diffInDays = dateDifference.day   // Expected days
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 2023-03-09
      • 2013-06-13
      • 1970-01-01
      相关资源
      最近更新 更多