nsdate

How to query and convert Parse.com Date to NSDate/String

限于喜欢 提交于 2020-01-06 08:35:08
问题 I want to take the parse column " createdAt ", query it and make it into a string that displays on the UI as a label to show the user when a product was posted and when it expires. There are similar questions on stackoverflow, but none have helped me and all have given me errors and crashes. I am using a TableViewController class and I'm querying 2 things: the productName and the timeCreated . (The productName I'm able to display in a cell without a problem.) I've tried several ways of

NSString compare is throwing exception SIGABT

大兔子大兔子 提交于 2020-01-06 08:01:18
问题 I have following code, where I'm comparing two string but its throwing exception. - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d { NSLog(@"calendarMonthView didSelectDate %@",d); //[self papulateTable]; //[table reloadData]; //[self performSelector:@selector(papulateTable) withObject:nil afterDelay:1.0]; NSString *tempDate = (NSString*)d; NSString *selectedDate = @"2013-02-04 00:00:00 +0000"; if([tempDate isEqualToString:selectedDate]) {

Adding two NSDate

假如想象 提交于 2020-01-04 07:55:51
问题 I've got two NSDate, date and time. I'd like to add them in such a manner that I get the date from date and time from time. Any suggestions on how I do this? Cheers Nik 回答1: Use NSCalendar s components:fromDate: to get the components of the two dates. Then reassemble them as needed using dateFromComponents:. 回答2: If I got you right NSDate s -dateByAddingTimeInterval: together with -timeIntervalSinceDate: are what you looking for. hth –f 回答3: I've got two NSDate, date and time. Sounds like you

Checking when a date has passed - Swift

拈花ヽ惹草 提交于 2020-01-04 05:46:08
问题 Well, the title pretty much says it all. What I am trying to do is check when a date has passed. So, for example let us say that a user is using my app and then they go to bed and check my app in the morning. When my app opens up I need to check if the day has changed at all. Also I don't really need to know this information when the app is terminated or in the background or anything. I just need to know if the date has changed when the app is running and the user is actually interacting with

Trim NSDate to show date only

喜欢而已 提交于 2020-01-04 04:04:30
问题 I have been through all the similar questions, unfortunately non could solve my problem so I asked it. I need my function to return an NSDate and only date, but my return value contains timing as well, I have tried the setTimeStyle noStyle and every possible solution I could come up with, here is the code: -(NSDate*)stringToDate{ NSString *dateString = @"01-02-2010"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *date;

how to build a NSPredicate filtering all days in a month using NSDate?

随声附和 提交于 2020-01-04 02:02:15
问题 Is there a way to get all days in a month generically ? Something like this: [NSPredicate predicatewithFormat@"(date.firstDayOfMonth >= @)AND(date.lastDayOfMonth <= @)"]; 回答1: Yes. You need to figure out what the first instant of the month is, as well as the first instant of the next month. Here's how I would do it: NSDate *now = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *nowComponents = [calendar components:NSEraCalendarUnit | NSYearCalendarUnit |

Finding the locale-dependent first day of the week

天大地大妈咪最大 提交于 2020-01-03 16:45:08
问题 Given an NSDate , how do I find the first day of that date's week, given the user's locale. For example, I've heard that some countries treat Monday as the first day of the week and others use Sunday. I need to return the preceding Monday in the first case but the preceding Sunday in the latter case. My best effort thus far always returns the preceding Sunday, regardless of the device settings applied: NSCalendar *calendar = [NSCalendar currentCalendar]; [calendar setLocale:[NSLocale

Converting NSString to NSDate adds one year in some cases

假如想象 提交于 2020-01-03 06:29:40
问题 I have some issues converting an NSString to NSDate since the end of the year. The code have always worked great before, but it suddenly started to behave wierd... For example 2013-01-05 becomes 2014-01-05 when converted to NSDate. Since it's a whole year it doesn't feel like it's the timezone spooking. It's not doing this with dates from 2012. Does anybody have an idea of what might be wrong? Code: NSString *dateString = postInfo.noteDate; NSString *newDateString = [dateString

Swift filter by NSDate object property

烂漫一生 提交于 2020-01-03 03:25:12
问题 I would like to filter my custom objects with a date property. For example: class Event { let dateFrom: NSDate! let dateTo: NSDate! init(dateFrom: NSDate, dateTo: NSDate) { self.dateFrom = dateFrom self.dateTo = dateTo } } Now i have a List of maybe 500 Events, and i just want to show the Events for a specific date. I could loop through all Objects, and create a new Array of Objects, but could i also use a filter? Ill tried something like this: let specificEvents = eventList.filter( { return

How to convert date string into format “17 Nov 2010”

流过昼夜 提交于 2020-01-02 23:02:39
问题 I have the date that is in format 2010-11-17 .This is of the form NSString . I want to convert this NSString date into format 17 Nov 2010 and display in a label This date is just not the current date but may even be the older dates. So I cant use the [NSDate date] instance to get the date. I tried using NSDateFormatter with the method dateFromString . But it gives me a null value. Here is the code snippet NSString *dates = @”2010-11-16”; NSDateFormatter *dateFormatter = [[NSDateFormatter