最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

[已解决]Swift中给当前NSDate增加一天

Swift crifan 108浏览 0评论

swift nsdate add seconds

ios – How to add minutes to current time in swift – Stack Overflow

iphone – How do i add 1 day to a NSDate? – Stack Overflow

ios – SWIFT: How do I add hours to NSDate object – Stack Overflow

let earliestMsgDate = NSDate()
print("earliestMsgDate=\(earliestMsgDate)")
let curCalendar:NSCalendar = NSCalendar.currentCalendar()
print("curCalendar=\(curCalendar)")
let prevDayOfEarliestMsgDate:NSDate = curCalendar.dateByAddingUnit(NSCalendarUnit.Day, value: –1, toDate: earliestMsgDate, options: [])!
print("prevDayOfEarliestMsgDate=\(prevDayOfEarliestMsgDate)")

效果:

earliestMsgDate=2015-12-13 04:48:48 +0000
curCalendar=<_NSCopyOnWriteCalendarWrapper: 0x7f955b434c30>
prevDayOfEarliestMsgDate=2015-12-12 04:48:48 +0000

如图:

转载请注明:在路上 » [已解决]Swift中给当前NSDate增加一天

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
18 queries in 0.208 seconds, using 9.85MB memory