1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| * (NSString *)getCurrentTimeString { NSDate *today = [NSDate date]; // NSInteger interval = [[NSTimeZone systemTimeZone] secondsFromGMTForDate: today]; // NSDate *localeDate = [today dateByAddingTimeInterval: interval];
NSDateFormatter _formatter = [[NSDateFormatter alloc] init] ; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; //hh与HH的区别:分别表示12小时制,24小时制 //设置时区,这个对于时间的处理有时很重要 //NSTimeZone_ timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"]; NSTimeZone* timeZone = [NSTimeZone systemTimeZone];
[formatter setTimeZone:timeZone];
//NSString * date_str = [localeDate description]; NSString * date_str = [formatter stringFromDate:today]; return date_str; }
|