nsdate

How to convert from NSDate(timeIntervalSince1970 to NSDate()?

末鹿安然 提交于 2019-12-11 04:35:20
问题 This is my code. But an error said, cannot invoke dateComponent with an argument list of type... let fromDate = NSDate(timeIntervalSince1970: TimeInterval(tweetsArray[indexPath.row].timestamp)!) let toDate = NSDate() let components : NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfMonth] let differenceOfDate = NSCalendar.current.dateComponents(components, from: fromDate, to: toDate) 回答1: In Swift 3, NSCalendar.current returns a Calendar , which is the Swift value wrapper type for the

Need advice about time comparison using NSDate

风格不统一 提交于 2019-12-11 04:29:51
问题 I am developing Alarm Clock. I want to compare a time now and setTime. Is it possible to compare in minutes only. My Problem is NSDate will compare in seconds, for example 9:38:50 is not equal to 9:38:00. how can I compare in minutes? 回答1: First, convert them to UNIX timestamp ignoring milliseconds. NSUInteger time1 = (NSUInteger)[date1 timeIntervalSince1970]; NSUInteger time2 = (NSUInteger)[date2 timeIntervalSince1970]; Ignore seconds. time1 = time1 - (time1 % 60); time2 = time2 - (time2 %

How to convert the date string into string( yyyy-MM-dd). While doing so, I getting null values?

岁酱吖の 提交于 2019-12-11 04:05:39
问题 I have the data as customerFromDate " 01 Apr 2010 " and customerToDate " 30 Apr 2010 " which is a string. I want to convert that format into the string "yyyy-MM-dd", but when doing so I got null values. Please see the following code which I had tried. printf("\n customerFromDate %s",[customerStatementObj.customerFromDate UTF8String]); printf("\n customerToDate %s",[customerStatementObj.customerToDate UTF8String]); /* prints as the following customerFromDate 01 Apr 2010 customerToDate 30 Apr

Get time from NSDate returns nil

时光毁灭记忆、已成空白 提交于 2019-12-11 04:04:14
问题 I am trying to show time on graph and i have a full time stamp in this @"2012-08-28 18:50:24" format. when i try to get time from this date then it returns nil in NSDate. NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *time = [formatter dateFromString:@"2012-08-28 18:50:24"]; in this code only if I change [formatter setDateFormat:@"HH:mm:ss"]; line to [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; then it starts working with full

IOS NSDate from string with time only

有些话、适合烂在心里 提交于 2019-12-11 03:48:58
问题 My task is to parse string with time to NSDate. And I do it very well with following code: NSString* timeStr = @"15:00:00" NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate* result = [formatter dateFromString:timeStr]; But as a result I get 2000-01-01 15:00:00 CET and I dont understand why

NSDate isMemberOfClass: [NSDate class] returns false? [duplicate]

冷暖自知 提交于 2019-12-11 03:44:54
问题 This question already has answers here : usage of isMemberOfClass; returning false (3 answers) Closed 4 years ago . this is bizarre. The following if statement is failing. What could be wrong? NSDate *date = [NSDate date]; if ([date isMemberOfClass: [NSDate class]]) { // Not executed. } 回答1: It happens that classes like NSArray , NSDictionary , NSString and NSData are class clusters. This concept is explained better in the documentation, and it means that you will not get a direct instance

Check if an array of custom objects contains an object with a certain date

↘锁芯ラ 提交于 2019-12-11 03:43:12
问题 I have an array of event objects . The object has several attributes. One of the attributes is an NSDate eve_date . Now I want to check if that array of objects contains a certain NSDate d I'm doing the following if([[matches valueForKey:@"eve_date"] containsObject:d]){ NSLog(@"contains object"); }else{ NSLog(@"does not contains object"); } But this is not working. Can anyone help me ? Kind regards EDIT Okay let me be more clear. I'm making a calendar app. I fetched all the events inside the

How to convert time String into NSDate?

人走茶凉 提交于 2019-12-11 02:39:24
问题 How can I convert time string (in 24h format) into NSDate for comparison? I get nil and wrong NSDate here: let a = "5:46" let b = "24:30" let dateFormatter = NSDateFormatter() dateFormatter.timeStyle = .ShortStyle dateFormatter.dateFormat = "k:mm" // k = Hour in 1~24, mm = Minute let outputA = dateFormatter.dateFromString(a) let outputB = dateFormatter.dateFromString(b) println("A: \(outputA) B: \(outputB)") Then I get A: Optional(1999-12-31 20:46:00 +0000) B: nil when I wish to get A: 5:46

Still having NSDateFormatter result issues even with NSTimezone properly set, why?

吃可爱长大的小学妹 提交于 2019-12-11 02:05:03
问题 The result is still a day before, I'm just asking myself why, because the NSTimeZone is properly set and is the right one for my country (italy, rome) here's my stub of code, any ideas? NSString *dateString = @"03/07/2008"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setFormatterBehavior:[NSDateFormatter defaultFormatterBehavior]]; [formatter setDateFormat:@"dd/MM/yyyy"]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setTimeZone:[NSTimeZone

Converting string to date returning the day before

自作多情 提交于 2019-12-11 01:46:51
问题 I have a date in a string with this format "2017-03-14" (yyyy-MM-dd) and i am trying to convert it into a string with this format "Tuesday, March 14, 2017". This is my code: let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" let date = dateFormatter.date(from: "2017-03-14") Now if i print the value of "date", i get this: 2017-03-13 22:00:00 +0000 This is just the day before. Why is that ? EDIT: I need to compare date before formatting it. var newDateString : String =