有关时间

将时间戳转化为秒数

[NSDate date].timeIntervalSince1970


默认时区的时间

NSDate *datenow = [NSDate date];


时间戳对应的时间

NSTimeZone *zone = [NSTimeZonesystemTimeZone];

NSDate *jifen = [datenow  dateByAddingTimeInterval:1430807556];


现在的时间

NSInteger interval = [zone secondsFromGMTForDate:datenow];

NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];


当前时间的时间戳的值

NSString *timeSp = [NSStringstringWithFormat:@"%ld", (long)[localeDatetimeIntervalSince1970]];


***********************************************

在tabelView中显示倒计时

//每次更新数据的时候要重新更新这个数组

//剩余时间得数组

_arr = [NSArray arrayWithObjects:[NSNumber numberWithInt:100], [NSNumber numberWithInt:200], [NSNumber numberWithInt:300], nil];


for (NSInteger i = 0; i < _arr.count; i++) {

        NSDictionary *dic =@{@"row":[NSStringstringWithFormat:@"%i", i],@"lastTime":_arr[i]};

        [totalLastTime addObject:dic];

}

//开启定时器方法:在viewDidLoad里调用 startTimer

- (void)startTimer

{

//每隔一分钟刷新

    timer = [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(refreshLessTime)userInfo:@""repeats:YES];

//如果不添加下面这条语句,在UITableView拖动的时候,会阻塞定时器的调用

    [[NSRunLoop currentRunLoop]addTimer:timerforMode:UITrackingRunLoopMode];

}

//主要的定时器中的方法,在该方法中,遍历totalLastTime,取出其中保存的lasttime和row,time用来显示,在显示完后自减,row代表对应显示的位置,在一次循环后,将新的time和没有改变的row从新替换totalLastTime中对应位置的元素,以此保证每一秒执行时,显示time都是最新的。

- (void)refreshLessTime

{

    NSInteger time;

    for (int i = 0; i < totalLastTime.count; i++) {

        time = [[[totalLastTimeobjectAtIndex:i] objectForKey:@"lastTime"]integerValue];

        NSIndexPath *indexPath = [NSIndexPathindexPathForItem:[[[totalLastTimeobjectAtIndex:i] objectForKey:@"row"]integerValue] inSection:0];

        TableViewCell *cell = (TableViewCell *)[_tableViewcellForRowAtIndexPath:indexPath];

        cell.label.text = [NSStringstringWithFormat:@"剩余支付时间:%@",[selflessSecondToDay:time]];

        NSDictionary *dic =@{@"row": [NSStringstringWithFormat:@"%i",indexPath.row],@"lastTime": [NSNumbernumberWithInteger:(time - 1)]};

        [totalLastTimereplaceObjectAtIndex:i withObject:dic];

    }

    [_tableView reloadData];

}



部分参考http://m.blog.csdn.net/blog/lidechen/43191779

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值