IOS关于大型网站抢购、距活动结束,剩余时间倒计时的实现代码

2025-05-29 0 15

2016年七夕抢购七夕底价直降,满268再减50!满468减100!大牌49元起!相约七夕情人节!欧美日韩名妆香水,2折秒杀爆款!绝对正品! 真心表爱意!限时抢购等活动拥有尽有。那么问题来了,基于代码是如何实现此功能的呢?不要着急,下面效果给大家带来了关于大型网站抢购、距活动结束,剩余时间倒计时的核心代码,一起看看吧。

关键代码如下所示:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30
/**

* 倒计时

*

* @param endTime 截止的时间戳

*

* @return 返回的剩余时间

*/

- (NSString*)remainingTimeMethodAction:(long long)endTime

{

//得到当前时间

NSDate *nowData = [NSDate date];

NSDate *endData=[NSDate dateWithTimeIntervalSince1970:endTime];

NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];

NSUInteger unitFlags =

NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;

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: %d Months: %d, Days; %d, Hours: %d, Mins:%d, sec:%d",

[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;

}

以上代码是IOS关于大型网站抢购、距活动结束,剩余时间倒计时的实现代码,代码比较简单,大家根据需求适当的添加修改删除代码,如果参考过程中发现有任何疑问欢迎给我留言,小编会及时回复大家的!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 IOS关于大型网站抢购、距活动结束,剩余时间倒计时的实现代码 https://www.kuaiidc.com/93068.html

相关文章

发表评论
暂无评论