- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何创建将处于 DST 模式的 NSDate。
我正在使用方法nextDaylightSavingTimeTransition
这是来自文档:
This property contains the date of the next (after the current instant) daylight saving time transition for the receiver. Depending on the time zone of the receiver, the value of this property may represent a change of the time zone's offset from GMT. Returns nil if the time zone of the receiver does not currently observe daylight saving time.
然后我验证它是否处于 DST 模式:
我正在使用方法:isDaylightSavingTimeForDate:
这是来自文档:
YES if the receiver uses daylight saving time at aDate, otherwise NO.
代码:
NSDate *nextDstTransition = [[NSTimeZone localTimeZone] nextDaylightSavingTimeTransition];
BOOL isDstOnForOldDate = [[NSTimeZone localTimeZone] isDaylightSavingTimeForDate:nextDstTransition];
很遗憾,我的 nextDstTransition
不在夏令时。我的假设与时区问题有关。
您能否分享有关在 DST 模式下创建 NSDate
的选项。
最佳答案
如果您仔细阅读文档:nextDaylightSavingTimeTransition:返回 DST 在给定日期之后更改的下一次时间,如果您处于 DST 从不更改(始终打开或始终关闭)的时区,则返回 nil。如果您的日期是夏令时,那么您就可以了,否则您需要知道它何时更改。
NSDate* date = ...
if (! [[NSTimeZone localTimeZone] isDaylightSavingTimeForDate:date]) {
NSDate* change = [[NSTimeZone localTimeZone] nextDaylightSavingTimeTransitionAfterDate:date];
if (change != nil) {
date = change;
} else {
// Tough, there is no DST in this time zone.
}
}
关于objective-c - 如何创建将处于 DST 模式的 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39250516/
我的应用程序中有两个 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
我是一名优秀的程序员,十分优秀!