- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个存储为自 1600 年 1 月 1 日以来我需要处理的天数的日期。这是我需要在我的应用程序中多次阅读的遗留日期格式。
以前,我一直在创建日历、空日期组件和根日期,如下所示:
self.gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar
] autorelease];
id rootComponents = [[[NSDateComponents alloc] init] autorelease];
[rootComponents setYear: 1600];
[rootComponents setMonth: 1];
[rootComponents setDay: 1];
self.rootDate = [gregorian dateFromComponents: rootComponents];
self.offset = [[[NSDateComponents alloc] init] autorelease];
[offset setDay: theLegacyDate];
id eventDate = [gregorian dateByAddingComponents: offset
toDate: rootDate
options: 0];
rootDate
时间不同在 iOS 与 Mac OS X 上。在 Mac OS X 上,我要到午夜了。在 iOS 上,我得到 8:12:28。 (到目前为止,这似乎是一致的。)当我添加我的天数后,奇怪的时间仍然存在。
最佳答案
我想你对闰秒/累积时钟变化解释时间问题是正确的。您正在处理的日期实际上是过去,还是纯粹是一个任意的时代?
无论哪种情况,您都可以尝试定义一个更接近现代的新纪元(例如, cocoa 纪元)。计算新纪元和旧纪元之间的天差,并将其保存为常数。当您需要处理日期时,将此增量应用于日期,然后使用您现有的 NSCalendar 技术,但使用新纪元而不是旧纪元。这有望避免您看到的时钟漂移问题。
关于cocoa-touch - 从 1600 年到 NSDate 的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4664582/
我的应用程序中有两个 UIDatePicker 控件,一个配置了 UIDatePickerModeDate,另一个配置了 UIDatePickerModeTime。 我想配置一个 NSDate 对象,
我可以通过此代码获取 iPhone 的当前日期 NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormatter1 = [[NSD
我在 Swift 中有一个模型,它有一个名为 expirationDate 的 NSDate 字段,我想根据当前时间计算过期前的剩余小时数日期。 有没有一种简单的方法可以利用现有的 NSDate 功能
我将我的 NSDate 存储到一个文件中,该文件采用您在 NSDate 上调用描述时获得的国际格式。 但是,我不知道如何从字符串格式返回到 NSDate 对象。 NSDateFormatter 似乎仅
我有兴趣创建一种方法来查找当前日期是否落在任何给定日期的特定时间之间。这是一个调度程序,所以我想找到当前时间正在发生什么事件。每天都有相同的时间集:820-900、900-940、940-1020 等
我有一个约会时间: Friday, July 8, 2016 at 6:30:00 PM India Standard Time 我想要这样的约会时间: Friday, July 8, 2016 at
我有一个 NSDate 对象。假设它代表“1-10-2011” NSDate *date = [df dateFromString:@"2011-10-01 00:00:00"]; 由于我所在的时区,
我从 Django API 获取 NSString 2012-08-17T10:56:45.508205 作为时间。 我正在尝试使用以下代码将该字符串转换为 NSDate 对象: NSDateForm
我在获取一系列 NSDates 与另一个 NSDates 范围相交的天数时遇到问题。 场景 1: 主要范围:3月8日-6月8日 检查范围:4月8日-5月8日 那么相交的天数就是4月8日-5月8日的天数
我知道如何获取两个 NSDate 之间的差异,如下所示 NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:anyPr
我需要根据另一个 NSDate 获取一天中特定时间的 NSDate。例如,如果我有一个代表 2015 年 5 月 10 日已知时间的 NSDate,我需要能够获得一个代表 2015 年 5 月 10
升级到1.2后出现编译错误: NSDate?! is not convertible to NSDate 代码: let dateCreated = photoCommentObjects[index
这是我的代码。但是一个错误说,不能用类型的参数列表调用 dateComponent... let fromDate = NSDate(timeIntervalSince1970: TimeInter
给定一个引用日期,我需要找到下面的“星期三”。 需要说明的是,如果引用日期是星期二,那么它应该返回同一周的星期三。 如果引用日期是星期三或更晚,则需要返回从下周开始的下一个星期三。 重要的是它不会返回
我有 NSDate* day1 和 NSDate* day2。我如何通过只复制第 1 天的年/月/日和第 2 天的小时/分钟/秒来制作 NSDate* day3? 最佳答案 unsigned unit
我有两个 NSDate 对象,我想要两者之间的差异,结果应该再次是一个 NSDate 对象。知道如何实现这一目标吗? 在这里,我试图解决一个独特的问题,我必须找出耗时,然后本地化耗时。如果我在 NSD
我试图强制用户使用日期选择器选择 future 的日期。我显然使用了compare:方法,但是,当我执行以下代码时,即使它与[NSDate date]相同的日期,它也会告诉执行if语句。这是我的代码:
我有两个用户选择的日期:开始日期和结束日期。它们是 NSDate 实例,我必须将它们作为 NSNumber 的参数发送。如何以秒为单位将它们转换为 NSNumber? 最佳答案 使用下面的代码: N
我对将 NSTimeInterval 转换为 NSDate 感到困惑,我有两个日期要比较,一个来自服务器,另一个在本地, 在服务器案例中,我以时间间隔格式获取日期,因此我也必须对本地数据执行相同的操作
我有一个从服务器获取的字符串 "yyyy-MM-dd'T'HH:mm:ss.SSS'Z"我通过这个 formate 将这个字符串转换成 NSDate。 class func convertUTCDat
我是一名优秀的程序员,十分优秀!