简体   繁体   English

如何在Swift中将当前星期的第一个日期设置为星期三?

[英]How to set the first date of current week to Wednesday in Swift?

How to set the first date of the week to Wednesday and show the first and last date of week on yellow bar? 如何将星期的第一天设置为星期三,并在黄色栏中显示星期的第一天和最后一天? Because the schedule will update every Wednesday. 因为时间表将在每个星期三更新。

应用设计截图

Please check this might help : 请检查这可能有帮助:

var calendar = Calendar.current
calendar.firstWeekday = 4

let startOfWeek = calendar.date(from: calendar.dateComponents([.yearForWeekOfYear, .weekOfYear], from: Date()))!    
let endOfWeek = calendar.date(byAdding: .day, value: 6, to: startOfWeek)!

print(startOfWeek)
print(endOfWeek)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM