- 一,轉化的方法爲
- 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);
ios NSDate NSTring long 時間戳與字符串轉換
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.