- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
NSDateComponents
week
自 iOS8 以来已弃用。 Apple 建议根据上下文使用 weekOfMonth
或 weekOfYear
,但它们的工作方式不同。例如:
components1 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date7DaysAgo]
toDate:[NSDate date]
options:0];
components1 返回 month = 0,week = 1,day = 0,weekOfMonth
和 weekOfYear
都等于 2147483647(整数最大值)。
components2 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date30DaysAgo]
toDate:[NSDate date]
options:0];
components2 返回 month = 1(我知道这取决于,但这只是一个例子),week = 0,day = 0,weekOfMonth
和 weekOfYear
都等于2147483647(整数最大值)。
Week
返回某个时间段内的周数(如果是一周或多周),它与月或年中的周数完全不同。为什么苹果会建议改用这个?
最佳答案
使用 NSWeekOfMonthCalendarUnit
或 NSWeekOfYearCalendarUnit
而不是 NSWeekCalendarUnit
。
关于ios - NSDateComponents 周在 iOS8 上的工作方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26120074/
我正在创建一个每周日历 View ,其中一部分是计算所显示的一周的第一天。我还希望保存的日期具有第一秒的时间,因此我试图确保日期的 hh:mm:ss 均为 00:00:00。 我有以下代码,在大多数情
我正在编写一些代码来获取服务器上的图像。图像文件名采用 yyyyMMdd_HHmm 格式(UTC),每 3 小时生成一次(1200,1500,1800,..等)。当代码启动时,我获取当前 UTC 日期
当我到达 2011 年 11 月 6 日时,我似乎无法弄清楚为什么这一天没有改变。我所做的只是遍历这些日子。任何帮助将不胜感激。这是我的代码: NSCalendar* calendar = [[NSC
我已经从Zaph阅读以下答案 iPhone - Correct way for getting current date and time for a given place / timezone a
如果您要运行此代码: // January 16th 2015 10:20 AM in Amsterdam var date = NSDate(timeIntervalSince1970: 14214
我有这段代码 NSDateComponents *comps = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCa
我正在使用多个 NSDateComponents 来显示一个时钟,其各个值在整个屏幕上被打散,但我遇到了格式化问题。 秒数显示为 1-60 而不是 00-59,小时数为 24 小时制而不是 12 小时
我有以下代码。当我在我的 iOS 3.1.3 设备上运行它时(克服它!)它按预期工作,但是当我在模拟器(iOS 5 和 4.3)上运行它时它会关闭 1 分 15 秒(9:01:15 ).这是因为我的代
我正在尝试获取两个日期之间的差异,它应该以天为单位显示。 NSLog(@"%@", [NSDate date]); NSDateFormatter *formatter = [[NSDateForma
我正在创建一个 NSDate。为什么一天总是少一天? 这是代码: NSDate *today = [NSDate date]; NSCalendar *gregorian = [[NSCalendar
为什么这给我错误的日期? NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCa
我一直在使用 Swift 和 Xcode 6.3.2 开发一个时钟应用程序,以下代码构建和运行得很好。 // Get current time let date = NSDate() let cale
我正在尝试从 2 个变量获取数据:hours = "08" 和 minutes = 30。我是这样做的: let calendar = NSCalendar(identifier: NSCalenda
我的问题是处理下面代码片段中给出的 NSDateComponents 操作的时间配置文件。 我有一个迭代大量 NSDate 对象的方法 该方法的一部分要求我放弃每个日期的小时、分钟和秒数。 为此,我有
我试图在 NSDateComponents 中设置时间,我编写了以下代码 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIden
我不明白为什么我不能使用 NSDateComponents 正确地更改 NSDate 的小时,我会这样做: NSDateComponent components = [calendar compone
一年有多少周?因为我在网上搜索过,我发现一年总共有 52.1 周,但是如果我在 Xcode 中这样做: NSCalendar *gregorian = [[NSCalendar alloc]
我希望显示来自 NSDate 对象的月数。 //Make Date Six Months In The Future NSCalendar *calendar = [[NSCalendar alloc
如果我有两个 nsdatecomponent 并且我想知道第一个对象中的 TIME 是否大于第二个。 例子: if (nsdatecomponentObject1 > nsdatecomponentO
我一直在使用 Swift 和 Xcode 6.3.2 开发一个时钟应用程序,以下代码构建和运行得很好。 // Get current time let date = NSDate() let cale
我是一名优秀的程序员,十分优秀!