我不认为这是可能的,因为日期格式会因此而受到干扰,然后您无法恢复到正确的日期格式。
但是如果你想要一本字典的格式,你可以使用此代码:
func getDatesToDictionary(dates: [Date]) -> [String: Any] {
let dateFormatterOne = DateFormatter()
dateFormatterOne.dateFormat = "MM-dd-YYYY HH:mm"
let dateFormatterTwo = DateFormatter()
dateFormatterTwo.dateFormat = "MM-dd-YYYY"
let fullDate = dateFormatterOne.string(from: dates[0])
let fullDateTemp = dateFormatterTwo.date(from: fullDate)
let finalDateString = dateFormatterTwo.string(from: fullDateTemp!)
var dateDictionary: [String: Any] = [:]
var dateArray: [Date] = []
let dateFormatterThree = DateFormatter()
dateFormatterThree.dateFormat = "HH:mm"
for eachDate in dates {
let fullDateHour = dateFormatterOne.string(from: eachDate)
let finalDateHourString = dateFormatterThree.date(from: fullDateHour)
dateArray.append(finalDateHourString!)
}
dateDictionary = [finalDateString: dateArray]
return dateDictionary
}
的UNIX的帖子列表时间戳 –
乘坐DateFormatter只有日期样式和相互比较数组对象,如果新的对象有相同的日期,然后采取一个字符串和追加日期第一然后每次如果日期是相同的,然后追加时间只有 – Pankaj
你是否正确地理解你想要一天的部分标题和小时行? –