ios NSDate NSTring long 時間戳與字元串變換

tags:    時間:2013-12-28 00:01:50
ios NSDate NSTring long 時間戳與字元串轉換
一,轉化的方法為     NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];     NSLog(@"timeSp:%@",timeSp); //時間戳的值  二,把獲取的時間轉化為當前時間  NSDate *datenow = [NSDate date];//現在時間,你可以輸出來看下是什麼格式     NSTimeZone *zone = [NSTimeZone systemTimeZone];     NSInteger interval = [zone secondsFromGMTForDate:datenow];     NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];     NSLog(@"%@", localeDate);  3.把時間戳轉化為時間的方法     NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];     NSLog(@"1363948516  = %@",confromTimesp);  //timer     NSDate *datenow = [NSDate date];//現在時間,你可以輸出來看下是什麼格式     NSTimeZone *zone = [NSTimeZone systemTimeZone];     NSInteger interval = [zone secondsFromGMTForDate:datenow];     NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];     NSLog(@"%@", localeDate);          NSString *timeSp = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];     NSLog(@"timeSp:%@",timeSp); //時間戳的值 1369189763711   1369218563 1369218614          NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1369189763711/1000];     NSLog(@"1363948516  = %@",confromTimesp);          //實例化一個NSDateFormatter對象      //判斷昨天 前幾天等 判斷今天凌晨時間戳     NSDateFormatter *dateFormatter1 = [[[NSDateFormatter alloc] init] autorelease];     [dateFormatter1 setDateFormat:@"yyyy-MM-dd 00:00:00"];     NSString *currentDateStr1 = [dateFormatter1 stringFromDate:[NSDate date]];     NSLog(@"凌晨時間:%@",currentDateStr1);     NSString *timeSp1 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];     NSLog(@"凌晨時間戳:%@",timeSp1);     //昨天凌晨時間戳     NSString *timeSp2 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]-24*60*60];     NSLog(@"昨天凌晨時間戳:%@",timeSp2); 

 

推薦閱讀文章

Bookmark the permalink ,來源:互聯網