IOS关于大型网站抢购、距活动结束,剩余时间倒计时的实现代码
2016年七夕抢购七夕底价直降,满268再减50!满468减100!大牌49元起!相约七夕情人节!欧美日韩名妆香水,2折秒杀爆款!绝对正品!真心表爱意!限时抢购等活动拥有尽有。那么问题来了,基于代码是如何实现此功能的呢?不要着急,下面效果给大家带来了关于大型网站抢购、距活动结束,剩余时间倒计时的核心代码,一起看看吧。
关键代码如下所示:
/**
*倒计时
*
*@paramendTime截止的时间戳
*
*@return返回的剩余时间
*/
-(NSString*)remainingTimeMethodAction:(longlong)endTime
{
//得到当前时间
NSDate*nowData=[NSDatedate];
NSDate*endData=[NSDatedateWithTimeIntervalSince1970:endTime];
NSCalendar*chineseClendar=[[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSUIntegerunitFlags=
NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
NSDateComponents*cps=[chineseClendarcomponents:unitFlagsfromDate:nowDatatoDate:endDataoptions:0];
NSIntegerHour=[cpshour];
NSIntegerMin=[cpsminute];
NSIntegerSec=[cpssecond];
NSIntegerDay=[cpsday];
NSIntegerMon=[cpsmonth];
NSIntegerYear=[cpsyear];
NSLog(@"FromNowto%@,diff:Years:%dMonths:%d,Days;%d,Hours:%d,Mins:%d,sec:%d",
[nowDatadescription],Year,Mon,Day,Hour,Min,Sec);
NSString*countdown=[NSStringstringWithFormat:@"还剩:%zi天%zi小时%zi分钟%zi秒",Day,Hour,Min,Sec];
if(Sec<0){
countdown=[NSStringstringWithFormat:@"活动结束/开始抢购"];
}
returncountdown;
}
以上代码是IOS关于大型网站抢购、距活动结束,剩余时间倒计时的实现代码,代码比较简单,大家根据需求适当的添加修改删除代码,如果参考过程中发现有任何疑问欢迎给我留言,小编会及时回复大家的!
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短