gpt4 book ai didi

ios:提前 3 周(按日期)

转载 作者:行者123 更新时间:2023-11-29 01:14:03 30 4
gpt4 key购买 nike

我需要比当前日期提前 3 周的日期。并将所有日期添加到数组中。我怎样才能得到这个?

 let date = NSDate()
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
let comps = calendar?.components([.Day, .WeekOfMonth, .Month], fromDate: date)
let days = calendar?.rangeOfUnit(NSCalendarUnit.Day, inUnit: NSCalendarUnit.Month, forDate: date)
print(days?.length)

这段代码给出了当月的天数。但下个月可能会出现 3 个弱点

for example today is 16.02 I need print something like this

16 17 18 19 20 21 22 23 24 25 26 27 28 29 01 02 04....

感谢提前

最佳答案

这个怎么样,它根据要求生成一个日期数组

    var date = NSDate()
var days : [String] = []

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd"

for _ in 0...20
{
days.append(dateFormatter.stringFromDate(date))

// move on to the next day
date = NSCalendar.currentCalendar().dateByAddingUnit(
.Day,
value: 1,
toDate: date,
options: NSCalendarOptions(rawValue: 0))!
}
print(days)

关于ios:提前 3 周(按日期),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35431811/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com