zoukankan      html  css  js  c++  java
  • 倒计时实现方法

    1. 开启定时器,1秒调用一次

    - (void)spareTimeRun  {

      self.timer = [NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(timerFireMethod:) userInfo:nilrepeats:YES];

    }

     

    2. 时间格式转化,用目标时间跟当前时间取得差时间。

    -(void)timerFireMethod:(NSTimer*)theTimer {

    TuanItemModel *tempGroupProductDic = [self._tuanList objectAtIndex:self.tuanPageIndex];

    NSString *string = tempGroupProductDic.endDate;

     

    NSDateFormatter *dateformatter =[[[NSDateFormatteralloc]init]autorelease];//定义NSDateFormatter用来显示格式

    [dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定格式

    NSDate *todate=[dateformatter dateFromString:string];

    NSCalendar *cal = [NSCalendarcurrentCalendar];//定义一个NSCalendar对象

    NSDate *today = [NSDate date];//得到当前时间

    //用来得到具体的时差

    unsignedint unitFlags = NSYearCalendarUnit |NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |NSMinuteCalendarUnit | NSSecondCalendarUnit;

    NSDateComponents *d = [cal components:unitFlags fromDate:today toDate:todate options:0];

    self.spareTimeLabel.text = [NSStringstringWithFormat:@"剩余时间%d%d%d%d", [d day],[d hour], [d minute], [d second]];

     

    //if ([d month]>0) {

    //self.spareTimeLabel.text = [NSString stringWithFormat:@"%d%d%d%d%d",[d month], [d day],[d hour], [d minute], [d second]];

    //}else {

    //self.spareTimeLabel.text = [NSString stringWithFormat:@"%d%d%d%d", [d day],[d hour], [d minute], [d second]];

    //}

    }

  • 相关阅读:
    jmeter 插件
    jmeter beanshell
    Linux awk&sed
    Linux 各文件系统配置
    Linux常用基本命令 1
    testNg自动化,读取excel的数据
    jmeter 控制器
    Web
    SQL语句
    HTML
  • 原文地址:https://www.cnblogs.com/jiangshiyong/p/2538301.html
Copyright © 2011-2022 走看看