#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (strong,nonatomic) UILabel *titleLable;

@property (strong,nonatomic) UILabel *showTimeLable;

@property (strong,nonatomic) UIView *bottomView;

@property (strong,nonatomic) NSString *setTime;

@property (strong,nonatomic) NSArray *timeArr;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(88, 40, 200, 140)];

self.titleLable.backgroundColor = [UIColor clearColor];

self.titleLable.numberOfLines = 0;

self.titleLable.textColor = [UIColor purpleColor];

self.titleLable.textAlignment = NSTextAlignmentCenter;

self.titleLable.font = [UIFont systemFontOfSize:30];

[self.view addSubview:self.titleLable];

self.showTimeLable = [[UILabel alloc] initWithFrame:CGRectMake(88, 190, 200, 200)];

self.showTimeLable.backgroundColor = [UIColor grayColor];

self.showTimeLable.textAlignment = NSTextAlignmentCenter;

self.showTimeLable.font = [UIFont systemFontOfSize:30];

self.showTimeLable.numberOfLines = 0;

self.showTimeLable.textColor = [UIColor yellowColor];

self.showTimeLable.layer.cornerRadius = self.showTimeLable.frame.size.width / 2;

self.showTimeLable.clipsToBounds = YES;

[self.view addSubview:self.showTimeLable];

self.setTime = @"2016-6-1";

self.timeArr = [self.setTime componentsSeparatedByString:@"-"];

[self refreshTime];

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshTime) userInfo:nil repeats:YES];

}

-(void)refreshTime

{

NSCalendar *laterCalender = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDateComponents *latercomponents = [[NSDateComponents alloc] init];

latercomponents.year = [self.timeArr[0] integerValue];

latercomponents.month = [self.timeArr[1] integerValue];

latercomponents.day = [self.timeArr [2] integerValue];

NSDate *laterDate = [laterCalender dateFromComponents:latercomponents];

NSDateComponents *betweenDate = [laterCalender components:NSCalendarUnitSecond fromDate:[NSDate date] toDate:laterDate options:0];

if (betweenDate.second < 0) {

self.showTimeLable.text = [self DayHourMunintSecond:-betweenDate.second];

self.titleLable.text = [NSString stringWithFormat:@"距离\n%@\n已经过时",self.setTime];

}

else{

self.showTimeLable.text = [self DayHourMunintSecond:betweenDate.second];

self.titleLable.text = [NSString stringWithFormat:@"距离\n%@\n结课还有",self.setTime];

}

}

-(NSString *)DayHourMunintSecond:(NSInteger)time

{

NSString *timeString;

timeString = [NSString stringWithFormat:@"%ld秒",time % 60];

time /= 60;

if (time > 0) {

timeString = [NSString stringWithFormat:@"%ld分\n%@",time % 60,timeString];

}

time /= 60;

if (time > 0) {

timeString = [NSString stringWithFormat:@"%ld时\n%@",time % 24,timeString];

}

time /= 24;

if (time > 0) {

timeString = [NSString  stringWithFormat:@"%ld天\n%@",time,timeString];

}

return timeString;

}

倒计时demo的更多相关文章

  1. unity3d之简单的时钟倒计时demo

    输入结束时间,开始倒计时,时间差不超过一天,附上代码:(关于个位数显示,加个判断如果小于10 显示的字符串加上0) using System.Collections; using System.Col ...

  2. js倒计时demo 天/时/分/秒

    <html><head> <meta charset="UTF-8"> <title>js简单时分秒倒计时</title> ...

  3. html—倒计时demo

    <!doctype html> <html> <head> <meta charset="utf-8"> </head> ...

  4. 倒计时的js实现 倒计时 js Jquery

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=987 一.如火如荼的团 ...

  5. 倒计时(jQuery)

    倒计时,在网页制作中会经常用到,特别是一些节日活动页面运用更是广泛.今天就和大家分享一下jQuery如何实现倒计时.话不多说,言归正传,倒计时开始: 首先,既然是用jQuery实现,那么前提就是要先引 ...

  6. js实现倒计时 类似团购网站

    一.demo与效果展示 为节约时间,我就直接套用了企鹅团的界面作为demo的背景.因为是倒计时,所以需要一个固定的时间,为了n年后,某位仁兄打开demo页面依然在倒计时,所以我把倒计时时间设成了205 ...

  7. js 发送短信倒计时、秒杀倒计时实现代码

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  8. Android倒计时功能的实现

    Android中的倒计时的功能(也能够直接使用CountDownTimer这个类直接实现,相关此Demo可查看我的博客).參考了网上写的非常好的一个倒计时Demo: watermark/2/text/ ...

  9. vue 倒计时返回首页

    1. vue页面15分钟无操作时返回首页 2. 基于vue的倒计时demo 3. 在vue2.0项目中一个简单的倒计时功能 4. vue重新发送验证码 5. 表格<td>里面文字垂直显示

随机推荐

  1. UEditor+七牛,实现图片直连上传

    最近做的项目,涉及到使用富文本编辑器,我选择了百度的UEditor.同时,我们的图片放在七牛云存储上.关于这两者间的集成,我写下一些个人的经验,与大家分享. 图片上传方案 目前来说,Web端基于七牛等 ...

  2. peepingtom

    简介 辅助评判网页渗透价值的自动化工具.它可以对制定IP和指定端口的所有http(s)服务进行快照,以一种易于浏览阅读的方式展示出来. 安装 git clone https://bitbucket.o ...

  3. 苹果4S

    港版.4S.白.非翻新机.16G.联通3G移动2G电信2G 1000 美版.4S.白.翻新.16G.联通3G移动2G电信3G 980

  4. Testing a Redux & React web application

    Part 1 - https://www.youtube.com/watch?v=iVKPbH3qyW0 Part 2 - https://www.youtube.com/watch?v=M5lwOs ...

  5. POJ题目(转)

    http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj29 ...

  6. MVC3+EF4.1学习系列(八)-----利用Repository and Unit of Work重构项目

    项目最基础的东西已经结束了,但是现在我们的项目还不健全  不利于测试 重复性代码多   层与层之间耦合性高  不利于扩展等问题.今天的这章 主要就是解决这些问题的.再解决这些问题时,自己也产生了很多疑 ...

  7. 官方解答:Vultr VPS常见问题

    VULTR VPS配置高,价格低廉,是非常优秀的vps品牌.今天我来翻译vultr官方FAQ,相信你能找到具体答案. Q 请介绍VULTR VPS机器硬件配置 Intel CPU 3+ GHz Cor ...

  8. Scala Tuple类型

    Tuple可以作为集合存储不同类型的数据,初始化实例如下: val tuple = (1,3,3.14,"aa") val third = tuple._3 Tuple 下标访问从 ...

  9. mongoDB4--mongoDB的增删改查

    MongoDb基本操作之增删改查我们知道传统关系型数据库的最常用操作就是"增加/删除/修改/查询",也就是传说中的CRUD(create/remove/updte/delete). ...

  10. 关于GVIM的配置。

    最近开始考虑从常用的 Dev-Cpp 和 Visual Studio 开发环境中转到gvim+gcc+gdb. 我一直觉得IDE很好方便,不是很明白别人这样的配置.但还是开始有意识的去尝试更换环境. ...