【问题标题】:Wrong week day of month?错误的星期几?
【发布时间】:2016-02-16 11:19:00
【问题描述】:

我正在尝试获取每月第一天的周索引。但它返回错误的值。我期待 2(星期一),但结果是 6(星期五)。可能是我错过了什么。

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setDay:1];
[dateComponents setMonth:1];
[dateComponents setYear:2016];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *date = [calendar dateFromComponents:dateComponents];

long weekDay = [calendar component:(NSCalendarUnitWeekday) fromDate:date];

【问题讨论】:

  • jan 1 st is --> 6 it is in friday., see this tamildailycalendar.com/…,
  • 你的编码是正确的
  • ... 或者您的意思是二月,但是您必须为月份整数指定 2。
  • 是的,我指的是 2 月份月份和星期的混合指数。感谢您的回复。

标签: ios objective-c nsdatecomponents


【解决方案1】:

2016 年 1 月 1 日是星期五。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 2014-11-15
    • 2017-12-10
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    相关资源
    最近更新 更多