[iOS]NSDate小节

NSDate *  senddate=[NSDate date];  

NSDateFormatter  *dateformatter=[[NSDateFormatter allocinit];  

[dateformatter setDateFormat:@"YYYYMMdd"];  

NSString *  locationString=[dateformatter stringFromDate:senddate];    

NSLog(@"locationString:%@",locationString);

 [dateformatter release]; 


2.


NSDate *date = [NSDate date];
    NSLog(@"date:%@",date);
    //系统时区
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSData *data = [zone data];
    NSLog(@"data:%@",data);
    //时间缩写
    NSString *abbStr = [zone abbreviation];
    NSLog(@"abbStr:%@",abbStr);
    //当地时区
    NSTimeZone *localTime = [NSTimeZone localTimeZone];
    NSLog(@"localTime:%@",localTime);
    //和格林尼治时间差
    NSInteger timeOff = [zone secondsFromGMT];
    //视察转化
    NSDate *timeOffDate = [date dateByAddingTimeInterval:timeOff];
    NSLog(@"timeOffDate:%@",timeOffDate);
    //所有地区名称
    NSArray *zoneArrs = [NSTimeZone knownTimeZoneNames];
    NSLog(@"zoneArrs:%@",zoneArrs);
    //遍历
    for (NSString *names in zoneArrs) {
        //时区
       NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:names];
        //设置格式
       NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:kCFDateFormatterFullStyle];
        [dateFormatter setTimeZone:timeZone];
         NSString *string = [dateFormatter stringFromDate:date];
        NSLog(@"string:%@,[timeZone name]:%@",string,[timeZone name]);
        [dateFormatter release];
        [timeZone release];
    }


你可能感兴趣的:(xcode)