標籤:轉換 test nsstring date div att amp sage class
1 //1.時間格式 2 NSDateFormatter *_dateFormatter = [[NSDateFormatter alloc] init]; 3 [_dateFormatter setDateFormat:@"YYYY年MM月dd天hh小時mm分ss秒"]; 4 5 //2.擷取系統時間 6 NSString *date = [_dateFormatter stringFromDate:[NSDate date]]; 7 8 //3.NSDate轉化為時間戳記 9 NSTimeInterval a=[date timeIntervalSince1970];10 11 //4.時間戳記轉化為NSDate12 NSDate *stampDate = [NSDate dateWithTimeIntervalSince1970:timeInter];13 14 //4.NSDate轉化為NSString15 NSString* dateString = [_dateFormatter stringFromDate:date];16 17 //5.傳入時間差,重設格式18 //傳入時間差,轉換格式19 - (NSString *)timeWithMessageString:(NSTimeInterval)timeInter20 {21 22 int month = timeInter / (3600 * 24 * 30);23 int day = timeInter / (3600 * 24);24 int hour = timeInter / 3600;25 int minute = timeInter / 60;26 27 int day_process = day - month * 30;28 int hour_process = hour - day *24;29 int minute_process = minute - hour *60;30 int miao_process = timeInter - minute*60;31 32 NSString *timedate = nil;33 if (day == 0) {34 timedate = [NSString stringWithFormat:@"%d小時%d分%d秒",hour_process,minute_process,miao_process];35 if (hour == 0) {36 timedate = [NSString stringWithFormat:@"%d分%d秒",minute_process,miao_process];37 if (hour == 0) {38 timedate = [NSString stringWithFormat:@"%d秒",miao_process];39 }40 }41 }else{42 timedate = [NSString stringWithFormat:@"%d天%d小時%d分%d秒",day_process,hour_process,minute_process,miao_process];43 }44 45 46 timedate = [NSString stringWithFormat:@"限時優惠: 還剩%@",timedate];47 return timedate;48 }
IOS--時間 NSDate,NSTimeInterval的一些轉換