1. 程式人生 > >ios 將時間戳轉為時間型別

ios 將時間戳轉為時間型別

       double lastactivityInterval = [[singleFriendDict objectForKey:@"lastactivity"] doubleValue]; 
        
        NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
        formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"MM月dd日 HH:mm"];
        

        NSDate* date = [NSDate dateWithTimeIntervalSince1970:lastactivityInterval];
     
        
        NSString* dateString = [formatter stringFromDate:date];
        
        lastActivityLabel.text = dateString;
        
        NSLog(@"format dateString:%@",dateString);