Swift. Calendar. veryShortWeekdaySymbols从Monday开始

5cg8jx4n  于 12个月前  发布在  Swift
关注(0)|答案(2)|浏览(137)

我想从星期一开始显示非常短的工作日符号。
当我在操场上这样做时:

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)


但结果是一样的

mqkwyuun

mqkwyuun1#

试试这个解决方案。

let firstWeekday = 2 // -> Monday

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

字符串
结果-> [“Mon”,“Tue”,“Wed”,“Thu”,“Fri”,“Sat”,“Sun”]

thtygnil

thtygnil2#

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

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

字符串

相关问题