一:
NSDateFormatter *dateFormater = [[NSDateFormatter alloc]init]; [dateFormater setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSTimeZone* localzone = [NSTimeZone localTimeZone]; NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0]; [dateFormater setTimeZone:GTMzone]; [dateFormater setTimeZone:localzone]; NSString *aStrDate = [[NSString alloc]initWithString:[dateFormater stringFromDate:[NSDate date]]]; NSString *sendText = [NSString stringWithFormat:@"app测试发送:%@", aStrDate]; NSLog(@"the send --> %@",sendText);
二:
- NSTimeZone* localzone = [NSTimeZone localTimeZone];
- NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:GLOBAL_TIMEFORMAT];
- [dateFormatter setTimeZone:GTMzone];
- NSDate *bdate = [dateFormatter dateFromString:GLOBAL_TIMEBASE];
- NSDate *day = [NSDate dateWithTimeInterval:(3600 + [localzone secondsFromGMT]) sinceDate:bdate];
- NSString *text = [dateFormatter stringFromDate:day];