NSDate 时区转换问题

一:

  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);

 

二:

  1. NSTimeZone* localzone = [NSTimeZone localTimeZone];  
  2. NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];  
  3. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
  4. [dateFormatter setDateFormat:GLOBAL_TIMEFORMAT];  
  5. [dateFormatter setTimeZone:GTMzone];  
  6. NSDate *bdate = [dateFormatter dateFromString:GLOBAL_TIMEBASE];  
  7. NSDate *day = [NSDate dateWithTimeInterval:(3600 + [localzone secondsFromGMT]) sinceDate:bdate];  
  8. NSString *text = [dateFormatter stringFromDate:day];  
posted @ 2013-08-16 12:51  cocoajin  阅读(564)  评论(0编辑  收藏  举报