我不知道如何编写正确的代码来解决我的日期问题
class Date {
class func from(#year:Int, month:Int, day:Int) -> NSDate{
var components = NSDateComponents()
components.year = year
components.month = month
components.day = day
let gregorianCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
let date = gregorianCalendar?.dateFromComponents(components)
return date!
}
这是错误信息 “NSGregorianCalendar”在 iOS 版本 8.0 中已弃用:使用 NSCalendarIdentifierGregorian 代替
但是当我替换下一行时不起作用
最佳答案
只需使用:
let calendar = NSCalendar.currentCalendar()
它将返回您的公历(取决于区域设置)。
另一个选项是定义常量并使用 GregorianCalendar 作为日历名称:
#ifdef __IPHONE_8_0
#define GregorianCalendar NSCalendarIdentifierGregorian
#else
#define GregorianCalendar NSGregorianCalendar
#endif
关于ios - 我如何解决 ios8 的日期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31639161/