我想从两个日期创建一个日期字符串,格式如下:
"Apr 21 - Sep 17, 2018" - US
"21 Apr - 17 Sep, 2018" - Elsewhere
同时尊重本地日期格式(美国的 MMM dd,欧洲的 dd MMM 等)。
如何让 DateFormatter 给我默认样式但没有年份?
let startDateFormatter = DateFormatter()
// How to keep medium style but without year?
// this is the US style,
// I want locale-independent style to match the other date formatter
startDateFormatter.dateFormat = "MMM dd"
let endDateFormatter = DateFormatter()
endDateFormatter.dateStyle = .medium
endDateFormatter.timeStyle = .none
let startDateText = startDateFormatter.string(from: startDate)
let endDateText = endDateFormatter.string(from: endDate)