Objective-C setting NSDate to current UTC

[NSDate date]; You may want to create a category that does something like this: -(NSString *)getUTCFormateDate:(NSDate *)localDate { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@”UTC”]; [dateFormatter setTimeZone:timeZone]; [dateFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSString *dateString = [dateFormatter stringFromDate:localDate]; [dateFormatter release]; return dateString; }

How to add one month to an NSDate?

You need to use NSDateComponents: NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; [dateComponents setMonth:1]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDate *newDate = [calendar dateByAddingComponents:dateComponents toDate:originalDate options:0]; [dateComponents release]; // If ARC is not used, release the date components

Comparing NSDates without time component

Use this Calendar function to compare dates in iOS 8.0+ func compare(_ date1: Date, to date2: Date, toGranularity component: Calendar.Component) -> ComparisonResult passing .day as the unit Use this function as follows: let now = Date() // “Sep 23, 2015, 10:26 AM” let olderDate = Date(timeIntervalSinceNow: -10000) // “Sep 23, 2015, 7:40 AM” var order … Read more

Get current NSDate in timestamp format

Here’s what I use: NSString * timestamp = [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000]; (times 1000 for milliseconds, otherwise, take that out) If You’re using it all the time, it might be nice to declare a macro #define TimeStamp [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000] Then Call it like this: NSString * timestamp = TimeStamp; … Read more

Difference between ‘YYYY’ and ‘yyyy’ in NSDateFormatter

Also when using a date format string using the correct format is important. @”YYYY” is week-based calendar year. @”yyyy” is ordinary calendar year. You can go through the whole blog, its a good to give it a look https://web.archive.org/web/20150423093107/http://realmacsoftware.com/blog/working-with-date-and-time http://realmacsoftware.com/blog/working-with-date-and-time (dead link)

get NSDate today, yesterday, this Week, last Week, this Month, last Month… variables

Adapted from the Date and Time Programming Guide: // Right now, you can remove the seconds into the day if you want NSDate *today = [NSDate date]; // All intervals taken from Google NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0]; NSDate *thisWeek = [today dateByAddingTimeInterval: -604800.0]; NSDate *lastWeek = [today dateByAddingTimeInterval: -1209600.0]; // To get the … Read more

How to Check if an NSDate occurs between two other NSDates

I came up with a solution. If you have a better solution, feel free to leave it and I will mark it as correct. + (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate { if ([date compare:beginDate] == NSOrderedAscending) return NO; if ([date compare:endDate] == NSOrderedDescending) return NO; return YES; }

How to get NSDate day, month and year in integer format?

Here you are, NSDate *currentDate = [NSDate date]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate]; // Get necessary date components [components month]; //gives you month [components day]; //gives you day [components year]; // gives you year You can use NSDateComponents for that as above. Please visit this page for details.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)