Swift。日历。 veryShortWeekdaySymbols 以星期一开始

Swift. Calendar. veryShortWeekdaySymbols start with Monday

我想从星期一开始显示非常短的工作日符号。

当我在操场上这样做时:

var calendar = Calendar.current
print(calendar.veryShortWeekdaySymbols)

结果是:["S", "M", "T", "W", "T", "F", "S"]

我也尝试更改 firstWeekday:

var calendar = Calendar.current
calendar.firstWeekday = 2
print(calendar.veryShortWeekdaySymbols)

但是结果是一样的

试试这个解决方案。希望这对你有用。

let firstWeekday = 2 // -> Monday

var symbols = calendar.veryShortWeekdaySymbols
symbols = Array(symbols[firstWeekday-1..<symbols.count]) + symbols[0..<firstWeekday-1]

结果 -> [“周一”、“周二”、“周三”、“周四”、“周五”、“周六”、“周日”]

您可以简单地删除第一个元素并附加它:

var weekdaySymbols = Calendar(identifier: .iso8601).veryShortWeekdaySymbols
weekdaySymbols.append(weekdaySymbols.remove(at: weekdaySymbols.startIndex))
weekdaySymbols  // ["M", "T", "W", "T", "F", "S", "S"]