获取当前时间字符串
- (NSString *)getCurrentDate
{
NSDateFormatter *formatter =[[[NSDateFormatteralloc] init] autorelease];
NSDate *date = [NSDate date];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSCalendar *calendar = [[[NSCalendaralloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [[[NSDateComponentsalloc] init] autorelease];
[comps setTimeZone:[NSTimeZonetimeZoneWithName:@"Asia/Shanghai"]];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
comps = [calendar components:unitFlags fromDate:date];
int year=[comps year];
NSString *month = ([comps month] < 10)?[NSStringstringWithFormat:@"0%d",[comps month]]:[NSStringstringWithFormat:@"%d", [comps month]];
NSString *day = ([comps day] < 10)?[NSStringstringWithFormat:@"0%d",[comps day]]:[NSStringstringWithFormat:@"%d", [comps day]];
NSString *hour = ([comps hour] < 10)?[NSStringstringWithFormat:@"0%d",[comps hour]]:[NSStringstringWithFormat:@"%d", [comps hour]];
NSString *min = ([comps minute] < 10)?[NSStringstringWithFormat:@"0%d",[comps minute]]:[NSStringstringWithFormat:@"%d", [comps minute]];
NSString *sec = ([comps second] < 10)?[NSStringstringWithFormat:@"0%d",[comps second]]:[NSStringstringWithFormat:@"%d", [comps second]];
NSString *curDate = [[[NSString alloc] initWithFormat:@"%d%@%@%@%@%@", year, month, day, hour, min, sec] autorelease];
return curDate;
}