1.
NSString*str=@"1368082020";//時(shí)間戳
NSTimeIntervaltime=[strdoubleValue]+28800;//因?yàn)闀r(shí)差問題要加8小時(shí) == 28800 sec
NSDate*detaildate=[NSDatedateWithTimeIntervalSince1970:time];
NSLog(@"date:%@",[detaildatedescription]);
//實(shí)例化一個(gè)NSDateFormatter對(duì)象
NSDateFormatter*dateFormatter = [[NSDateFormatteralloc]init];
//設(shè)定時(shí)間格式,這里可以設(shè)置成自己需要的格式
[dateFormattersetDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString*currentDateStr = [dateFormatterstringFromDate:detaildate];
2.
-(NSString *)TimeStamp:(NSString *)strTime
{
//實(shí)例化一個(gè)NSDateFormatter對(duì)象
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//設(shè)定時(shí)間格式,這里可以設(shè)置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//用[NSDate date]可以獲取系統(tǒng)當(dāng)前時(shí)間
NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
//輸出格式為:2010-10-27 10:22:13
NSLog(@"%@",currentDateStr);
//alloc后對(duì)不使用的對(duì)象別忘了release
[dateFormatter release];
return currentDateStr;
}