zoukankan      html  css  js  c++  java
  • iOS 电商购物车倒计时时间计算

    /**
     * 倒计时
     *
     * @param endTime 截止的时间戳
     *
     * @return 返回的剩余时间
     */
    - (NSString*)remainingTimeMethodAction:(long long)endTime
    {
        //得到当前时间
        NSDate *nowData = [NSDate date];
        
        //把时间戳转换成date格式
        NSDate *endData=[NSDate dateWithTimeIntervalSince1970:endTime];
        
        //创建日历对象
        NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSCalendarIdentifierGregorian ];
        
        //设置单元标识 小时 分钟 秒 天 月 年
        NSUInteger unitFlags =
        NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear;
        
        //给出开始时间 和 结束时间 获取单位标识的数据
        NSDateComponents *cps = [chineseClendar components:unitFlags fromDate:nowData toDate: endData options:0];
        NSInteger Hour = [cps hour];
        NSInteger Min = [cps minute];
        NSInteger Sec = [cps second];
        NSInteger Day = [cps day];
        NSInteger Mon = [cps month];
        NSInteger Year = [cps year];
        
        NSLog( @" From Now to %@, diff: Years: %ld Months: %ld, Days; %ld, Hours: %ld, Mins:%ld, sec:%ld",
              [nowData description], Year, Mon, Day, Hour, Min, Sec);
        NSString *countdown = [NSString stringWithFormat:@"还剩: %zi天 %zi小时 %zi分钟 %zi秒 ", Day,Hour, Min, Sec];
        if (Sec<0) {
            countdown=[NSString stringWithFormat:@"活动结束/开始抢购"];
        }
        return countdown;
    } 
  • 相关阅读:
    网线
    第19次实验
    矩阵乘法
    20次试验
    视频笔记
    1
    effective C++ 条款 34:区分接口继承和实现继承
    effective C++ 条款 35:考虑virtual函数以外的其他选择
    effective C++ 条款 29:为“异常安全”而努力是值得的
    effective C++ 条款 27:尽量少做转型动作
  • 原文地址:https://www.cnblogs.com/xiaobai51/p/6285031.html
Copyright © 2011-2022 走看看