import Foundation
class DateHandler {
private static let stringOffset : Int = 10
static var todaysDate: String {
return formatDateString(date: Date())
}
static var tomorrowDate: String {
guard let tommorrowDate = Calendar.current.date(byAdding: .day,value:1, to: Date()) else {return ""}
return formatDateString(date: tommorrowDate)
}
private static func formatDateString(date:Date)->String {
let dateString = String(describing:date)
let endIndex = dateString.index(dateString.startIndex, offsetBy:self.stringOffset)
return dateString.substring(to:endIndex)
}
}
我在天气应用程序中它给我警告tring切割下标部分范围达到'操作