国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

倒計時--時分秒

2019-11-09 17:46:28
字體:
來源:轉載
供稿:網友
//[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];  //- (void)timerFireMethod:(NSTimer *)theTimer {    BOOLtimeStart = YES;     NSCalendar *cal = [NSCalendar currentCalendar];//定義一個NSCalendar對象    NSDateComponents *endTime = [[NSDateComponents alloc] init];    //初始化目標時間...    NSDate *today = [NSDate date];    //得到當前時間          NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];     [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];    NSDate *dateString = [dateFormatter dateFromString:todate];     NSString *overdate = [dateFormatter stringFromDate:dateString]; //    NSLog(@"overdate=%@",overdate);     staticint year;     staticint month;     staticint day;     staticint hour;     staticint minute;     staticint second;     if(timeStart) {//從NSDate中取出年月日,時分秒,但是只能取一次        year = [[overdate substringWithRange:NSMakeRange(0, 4)] intValue];         month = [[overdate substringWithRange:NSMakeRange(5, 2)] intValue];         day = [[overdate substringWithRange:NSMakeRange(8, 2)] intValue];         hour = [[overdate substringWithRange:NSMakeRange(11, 2)] intValue];         minute = [[overdate substringWithRange:NSMakeRange(14, 2)] intValue];         second = [[overdate substringWithRange:NSMakeRange(17, 2)] intValue];         timeStart= NO;     }          [endTime setYear:year];     [endTime setMonth:month];     [endTime setDay:day];     [endTime setHour:hour];     [endTime setMinute:minute];     [endTime setSecond:second];     NSDate *overTime = [cal dateFromComponents:endTime]; //把目標時間裝載入date    //用來得到具體的時差,是為了統一成北京時間    unsignedintunitFlags = NSYearCalendarUnit| NSMonthCalendarUnit| NSDayCalendarUnit| NSHourCalendarUnit| NSMinuteCalendarUnit| NSSecondCalendarUnit;    NSDateComponents *d = [cal components:unitFlags fromDate:today toDate:overTime options:0];     NSString *t = [NSString stringWithFormat:@"%d", [d day]];     NSString *h = [NSString stringWithFormat:@"%d", [d hour]];     NSString *fen = [NSString stringWithFormat:@"%d", [d minute]];     if([d minute] < 10) {         fen = [NSString stringWithFormat:@"0%d",[d minute]];     }    NSString *miao = [NSString stringWithFormat:@"%d", [d second]];     if([d second] < 10) {         miao = [NSString stringWithFormat:@"0%d",[d second]];     }//    NSLog(@"===%@天 %@:%@:%@",t,h,fen,miao);     [_longtime setText:[NSString stringWithFormat:@"%@天 %@:%@:%@",t,h,fen,miao]];    if([d second] > 0) {         //計時尚未結束,do_something//        [_longtime setText:[NSString stringWithFormat:@"%@:%@:%@",d,fen,miao]];     }elseif([d second] == 0) {         //計時結束 do_something               }else{//計時器失效        [theTimer invalidate];     }      }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼伦贝尔市| 依兰县| 咸阳市| 凉山| 大悟县| 兰坪| 墨玉县| 拉萨市| 大连市| 许昌市| 拉孜县| 太仆寺旗| 周口市| 开阳县| 威信县| 阿尔山市| 酒泉市| 长寿区| 双辽市| 星座| 南漳县| 绥滨县| 四子王旗| 白银市| 山东省| 沁阳市| 石泉县| 哈巴河县| 五寨县| 铜梁县| 化州市| 大同市| 忻州市| 三明市| 丰城市| 平谷区| 郎溪县| 玉溪市| 朝阳区| 光泽县| 名山县|