nsdate

NSPredicate with NSDate filtering by day/month but not year

谁说胖子不能爱 提交于 2019-12-24 06:58:47
问题 I need to create a predicate which needs to filter a list of objects using the property creationDate which is a NSDate object. I want to obtain the list of objects that have the same day and month, but not the same year. Practically, I want the objects that occurred today (as day/month) in the past. How can I create this predicate? For example : today is July 27th 2016 and I want all the objects that have July 27th as creationDate. 回答1: First, to extract a day and month from a date...

Combining time and date in ISO8601 format string using Swift

久未见 提交于 2019-12-24 03:44:11
问题 I have two texfields representing date and time from the date picker, but when I parse the string only the date is displayed. I would like to combine date and time into a string in ISO8601 format (e.g. 2015-06-11T00:00:00.000Z ) and send it to the server. 回答1: You can do it using NSCalendar method dateBySettingHour as follow: Xcode 8.2.1 • Swift 3.0.2 let df = DateFormatter() df.calendar = Calendar(identifier: .iso8601) df.locale = Locale(identifier: "en_US_POSIX") df.dateFormat = "yyyy-MM-dd

How to parsing NSDate to RFC 822 always use in English?

萝らか妹 提交于 2019-12-24 03:35:19
问题 I need to PUT a RESTful to server. the Date must use like Sat, 19 Jan 2013 04:09:58 GMT . in objc I wrote this: NSDateFormatter* _GMTDateFormatter = [[NSDateFormatter alloc] init]; [_GMTDateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss"]; [_GMTDateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString* theDate = [_GMTDateFormatter stringFromDate:[NSDate date]]; theDate = [theDate stringByAppendingString:@" GMT"]; NSLog(@"%@",theDate); it will be output Sat, 19 Jan

Sort NSDate without respect to the time of day - just the date

不想你离开。 提交于 2019-12-24 03:07:41
问题 I have an array controller with keys of nextCheck (NSDate), lastName (NSString), and firstName (NSString). I have set the sort descriptors for the array. As you can see below, I am sorting by nextCheck first, then lastName, then firstName. This appears to not be working because the NSDate is made up of not only a date component but also a time component. Is there an easy way to sort by the date component only? [_arrayCurrentVisits setSortDescriptors:[NSArray arrayWithObjects:[NSSortDescriptor

NSDate : timeIntervalSinceNow crash

落爺英雄遲暮 提交于 2019-12-24 02:37:16
问题 I want to display, on screen, the elapsed time since some event. I have a member variable NSDate *_startTime; I allocate it (and initiate a timer) like so: _startTime = [NSDate date]; _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(clock) userInfo:nil repeats:YES]; My clock function gets called fine but when I attempt to find the elapsed time I get a crash with no real way of determining what happens; I simple get EXC_BAD_ACCESS . Below is how I attempt to

How can I find out whether an NSDate is a business day?

耗尽温柔 提交于 2019-12-24 01:51:04
问题 How can I find out whether an NSDate is a business day? That is to say, whether or not it is a weekend according to the user's current locale and calendar settings - so not hardcoded to just be Monday to Friday? NSCalendar has a firstWeekday property, but that just seems to be a presentational thing; it's Sunday in the US and Monday in the UK. EDIT: I'm not worried about holidays, I just want to be able to shade the weekends of a calendar in the same way as the built-in calendar app. 回答1:

PHFetchResults date filter not generating correct results for time range

落花浮王杯 提交于 2019-12-24 00:44:27
问题 I am trying to fetch images from photo library within the range of two dates and I am getting the images successfully. Using PHAsset Library Now the problem is that am not able to get images between two times of the same day like between 12:10PM to 12:30PM Using below code NSDate *startDate = [self getDateForDay:30 andMonth:9 andYear:2016 andHour:12 andMinute:10 andSecond:0]; NSDate *endDate = [self getDateForDay:30 andMonth:9 andYear:2016 andHour:12 andMinute:30 andSecond:0]; -- -(NSDate*)

Invalid parameter not satisfying: date

痴心易碎 提交于 2019-12-24 00:28:12
问题 I'm having an issue coming in from Crashlytics. I have debugging parameters on so I am seeing what parameters there are. datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]]; NSLog(@"Time: %@",startTimeString); NSLog(@"Date: %@", appointment.date); [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];

How to convert a date given as “20110912T220000”(NSString) to NSDate

天大地大妈咪最大 提交于 2019-12-23 22:34:34
问题 I am getting start and end dates for my calendar event(while parsing a .ics file) in "20110912T220000" format. How can I convert this to a NSDate to add to add as event(EKEvent)'s startDate property. If anyone knows please help me soon. 回答1: You should use NSDateFormatter for this. See Data Formatting Guide (the Date & Time Programming Guide may also be interesting) This is also detailed in this Technical Note in Apple's Q&As. Note that for such situations, you should use the special "en_US

Swift - NSDate - remove part of date

﹥>﹥吖頭↗ 提交于 2019-12-23 19:13:01
问题 I have a date in following format 2015-02-22T20:58:16+0000 In order to convert it to NSDate I found following solution var df = NSDateFormatter() df.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ" var date = df.dateFromString(myDate) df.dateFormat = "eee MMM dd yyyy" var dateStr = df.stringFromDate(date!) But I want to remove +0000 from date. I tried to remove ZZZZm but app crashes. How can I remove extra +0000 digits ? 回答1: You ask: How can I remove extra +0000 digits? I'm not sure what you mean,