Tag: nsdate

iPhone – 比较date不按预期工作

我有一个设置为特定date的事件。 我想检查date是否在当前date的5分钟范围内。 例如:如果事件设置为晚上9:10,现在是晚上9:02。 我想看看目前的时间是在9点05分到9点15分之间。 所以,我呢… NSDate *currentDate … this variable contains the current date NSDate *plusFive = [eventDate dateByAddingTimeInterval:300]; NSDate *minusFive = [eventDate dateByAddingTimeInterval:-300]; NSComparisonResult result1 = [eventDate compare:minusFive]; NSComparisonResult result2 = [eventDate compare:plusFive]; if ( (result1 == NSOrderedAscending) && (result2 == NSOrderedDescending) ) { // if the current date is not inside the 5 […]

通过NSDate重新sortingdynamicUITableView

在我的应用程序中,我有一个UITableView将填充核心date项目。 正如你可以在这篇文章中看到的,我已经要求一个sortingfunction: https : //stackoverflow.com/a/36703648/6012187 func ReSort() { CoreDataItems.sortInPlace({sortAscending ? $0.RowName < $1.RowName : $0.RowName > $1.RowName}) sortAscending = !sortAscending tableView.reloadData() } 现在我的问题是,我如何dynamic设置RowName值? 例如。 我保存用户默认的RowName。 但$0.defaults.objectForKey("xx")不起作用没有语法错误 下一个问题是: 我如何sorting一行,哪个值是一个NSDate?

如何得到无价值的NSDate

我是Swift和一般编码的初学者。 现在我正在尝试开发一段代码来设置每天一次的动作的时间限制。 @IBAction func yesButtonPressed(sender: AnyObject) { //To retrive the control date value. First time it has nil value var controlDate = NSUserDefaults.standardUserDefaults().objectForKey("controlDate") as? NSDate //To check current date to compare with var currentDate = NSDate() // To check if time interval between controlDate and currentDate is less than 1 day var timeInterval = controlDate?.timeIntervalSinceNow […]

在iOS文档中使用rfc3339dateFormatter作为示例之后,dateFromString返回nil

我想通过parsing以下方式从NSString获取NSDate: NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [rfc3339DateFormatter setLocale:enUSPOSIXLocale]; [rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; [rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString *createdString = [NSString stringWithFormat:@"2014-08-27T17:10:36.000+05:30"]; NSDate *createdDate = [rfc3339DateFormatter dateFromString:createdString]; 这里createdDate被返回为零。 我在这里错过了什么? 也请澄清我的timeZone和区域设置的正确使用。

如何在Swift 2.0中减less当前date的几分钟

如何从当前时间减less5或10分钟,然后将其作为date格式存储在Swift 2.0中? let now = NSDate() var reducedTime = ???? \\ Here I want 10 minutes reduced from current time. 如果当前时间是02:20:00,那么reducedTime应该是02:10:00我怎样才能以最简单的方式做到这一点 ?

NSDate dateWithTimeIntervalSince1970不返回GMT / UTC时间

我尝试了一个实验,因为我需要能够在我正在工作的应用程序中生成一个unix时间戳(自1970年以来)。 NSLog(@"Getting timeIntervalSince1970"); double theLoggedInTokenTimestampDateEpochSeconds = [[NSDate date] timeIntervalSince1970]; 这应该已经在格林尼治标准时间(1970年1月1日以来的秒)内返回了纪元秒(自1970年以来)。 但是,在2011年8月15日星期一09:54:30进行实验时,返回1313427270.504315 在Mac OSterminal上用一个简单的perl单行testing,得到: perl -e 'print scalar(localtime(1313427270))' ,它返回星期一8月15日09:54:30 2011 … 这显然不是格林威治时间,当我在SF湾区,当地时区设置为“库比蒂诺”。 怎么回事,请问我该如何解决? 我需要让我的应用程序在通信时向服务器发送UTC时间,所以无论用户在什么时间时间戳都会在一个相同的有效时区内发送。 在我的应用程序的另一部分,当用户从服务器请求数据,它获取它以UTC发送 ​​- 将其转换为显示如下: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[NSLocale currentLocale]]; [dateFormatter setTimeZone:nil]; [dateFormatter setDateFormat:@"yyyyMMdd"]; NSDate *conversationDate = [NSDate dateWithTimeIntervalSince1970:[theConversationTimeStampString intValue]]; NSString *conversationDateString = [dateFormatter stringFromDate:conversationDate]; [dateFormatter release]; 而且这个工程很漂亮 – 在用户的时区和区域显示更正的时间…所以我知道正在完成传入的时间戳。 […]

形成一个谓词来过滤date之间

说我有两个date: minDate:2012-08-29 12:22:17 +0000 maxDate:2011-12-01 18:14:38 +0000 我有一个叫做MBDate的核心数据对象,它有一个NSDate属性。 我想要得到所有MBDate的日子,包括在上述日子之间。 所以它应该忽略小时,秒和分钟,并且只需要在8/29 – 12/01之间的所有日子。 就像是: predicate = [NSPredicate predicateWithFormat:@"date < %@ AND date > %@", maxDate, minDate]; 但我不确定我会怎样告诉它无视时间和分钟,只看日子。 有任何想法吗?

更改当前date

我正在使用iPhone开发中的date。 我需要从当前date起24小时增加date。

这种方法总是给我当天的12:00:00在ios?

是的,这与NSDate开始的一天和一天的结束是类似的,但是这个话题并没有讨论它是否适用于我在这里问的所有情况。 这个问题处理不回正确的价值,因为他们忘了NSDayCalendarUnit。 这个问题正在处理的价值的准确性,因为它原来是不会像我怀疑的DST工作。 在我的应用程序的几个部分,我需要指定一天的时间,而不关心实际的一天,例如,在每天下午4:00做这个活动。 我已经看过几篇关于如何做到这一点的文章,但是希望对我的方法有所反馈。 以下方法旨在返回任何特定日子的午夜,并将与表示特定时间(例如,上午1:00:00为3600)的秒数的偏移一起使用。 我相信它应该可以工作,但是我很好奇它是否会处理像夏时制这样的边缘案例。 对于任何反馈,我们都表示感谢。 谢谢! // We want to return 12:00:00AM of the day represented by the time interval NSTimeInterval getStartOfDay(NSTimeInterval t) { // first convert the time interval to an NSDate NSDate *ourStartingDate = [NSDate dateWithTimeIntervalSinceReferenceDate:t] ; // get just the year, month, and day of our date unsigned unitFlags […]

如何在TAPKU日历中检查NSDatedate

我正在使用核心数据来存储我的项目的对象。对象中有一个date字段。我想检查与Tapku日历组件的iPhone点击date。 我的对象上的date是格式 2011-01-10这是一个本地化的date。 我如何检查date从tapku日历控件返回的date。