我正在使用插件SwiftDate来处理NSDate。但我有一个问题,weekOfYear
日期2015-08-08
(星期六)不等于日期weekOfYear
(星期日)的2015-08-08
,我认为{{1}的问题但是我不知道如何改变它。这是代码:
. firstDayOfWeek
有人可以帮忙吗?我真的需要这个!
答案 0 :(得分:0)
这应该有效:
let calendar = NSCalendar.currentCalendar();
calendar.firstWeekday = 2;
let date1: NSDate = NSDate.date(fromString: "2015-08-08", format: DateFormat.Custom("yyyy-MM-dd"))!
let date2: NSDate = NSDate.date(fromString: "2015-08-09", format: DateFormat.Custom("yyyy-MM-dd"))!
var weekNum1 = calendar.components(NSCalendarUnit.CalendarUnitWeekOfYear, fromDate: date1).weekOfYear;
var weekNum2 = calendar.components(NSCalendarUnit.CalendarUnitWeekOfYear, fromDate: date2).weekOfYear;
if(weekNum1 != weekNum2){
//do here
}