Why do I get "2010-01-01 00:00:00 +900" from "2010-12-31 15:00:00 +000"?

Discussion in 'iOS Programming' started by mikezang, Dec 31, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I have NSDate, it will be shown as below if I used NSLog(@"%@", date.description);
    2010-12-31 15:00:00 +0000

    it will be shown as if I used NSLog(@"%@", [date descriptionWithLocale:[[NSLocale currentLocale] localeIdentifier]]);
    Saturday, January 1, 2011 12:00:00 AM Japan Standard Time

    But it will be show as below if I used NSLog(@"%@", [date formattedDateString]);
    2010-01-01 00:00:00 +0900

    Code:
     
    - (NSString *)formattedDateString {
        return [self formattedStringUsingFormat:@"YYYY-MM-dd HH:mm:ss ZZZ"];
    }
     
    - (NSString *)formattedStringUsingFormat:(NSString *)dateFormat {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:dateFormat];
        NSString *ret = [formatter stringFromDate:self];
        [formatter release];
        return ret;
    }
    
    Where do I make mistake?
     
  2. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #2
    I got what I need if I used NSLog(@"%@", [date formattedDateString]);
    2011-01-01 00:00:00 +0900

    Code:
    - (NSString *)formattedDateString {
        return [self formattedStringUsingFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
    }
     

Share This Page