ios - 将 30 秒添加到 NSDate

标签 ios cocoa-touch nsdate uilocalnotification date-arithmetic

这个问题在这里已经有了答案:





How to add a time interval to an NSDate?

(5 个回答)


6年前关闭。




我如何转换 NSDate要秒?我需要它在几秒钟内,以便我可以将 30 秒添加到日期然后转换回 NSDate安排本地通知。任何更好的方法也是受欢迎的。

最佳答案

您可以使用 dateByAddingTimeInterval并将值作为 30 传入。这将返回 NSDate这将提前 30 秒。

NSDate *newDate = [previousDate dateByAddingTimeInterval:30];

关于ios - 将 30 秒添加到 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862599/

相关文章:

Ios 7 自定义 UINavigationController 动画因目标 Controller 中的 mapView 而失败

ios - AV播放器 "Cannot Complete Action"

ios - xctool 无法清理我的 iOS 项目

ios - 应用程序在 iPhone 中以黑屏启动

iphone - 我的 UITabBarController 的 didSelectViewController 方法没有被调用?

iphone - CALayer蒙版去除?

ios - 在 .Day 中快速比较两个 NSDate 给出了错误的结果

iphone - 当声音在 AVAudioPlayer 中播放完毕时执行操作吗?

iphone - 如何使用 CFNetwork 处理 iOS 上的互联网连接中断?

ios - NSDate 到 String 的转换并显示在 UILabel 中