最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Swift crifan 3313浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.240 seconds, using 22.18MB memory