NSString*str= [NSString stringWithFormat:@"%@",list.btime];//時間戳
NSTimeInterval time=[str doubleValue]/1000;
NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
//實例化一個NSDateFormatter對象
NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
//設定時間格式,這里可以設置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
時間轉時間戳的方法:
NSString *timeSp =
[NSString stringWithFormat:@"%d", (long)[datenow
timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //時間戳的值
時間戳轉時間的方法
NSDate *confromTimesp =[NSDate dateWithTimeIntervalSince1970:1296035591];
NSLog(@"1296035591= %@",confromTimesp);
NSString*confromTimespStr = [formatter stringFromDate:confromTimesp];
NSLog(@"confromTimespStr=%@",confromTimespStr);
時間戳轉時間的方法:
NSDateFormatter*formatter=[[NSDateFormatteralloc]init];
[formattersetDateStyle:NSDateFormatterMediumStyle];
[formattersetTimeStyle:NSDateFormatterShortStyle];
[formattersetDateFormat:@"yyyyMMddHHMMss"];
NSDate*date=[formatterdateFromString:@"1283376197"];
NSLog(@"date1:%@",date);
[formatterrelease];