Get current date string

- (NSString*)getCurrentDateString { // get current date object NSDate *date = [NSDate date]; // get calendar object NSCalendar *calendar = [NSCalendar currentCalendar]; // set flags that you need int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; // get date components NSDateComponents *dateComps = [calendar components:flags fromDate:date]; // create string. format you like. NSString *dateString = [@"" stringByAppendingFormat:@"%d/%d/%d %d:%d:%d", dateComps.year, dateComps.month, dateComps.day, dateComps.hour, dateComps.minute, dateComps.second]; // for debug // NSLog(@"%@", dateString); return dateString; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.