#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. [BZOJ2339][HNOI2011]卡农

    [BZOJ2339][HNOI2011]卡农 试题描述 输入 见"试题描述" 输出 见"试题描述" 输入示例 见"试题描述" 输出示例 见& ...

  2. mongodb集群+分片部署(二)

    机器:10.165.38.68    10.165.38.72 部署包:mongodb-linux-x86_64-rhel55-3.0.2.tgz(百度云盘下载地址:http://pan.baidu. ...

  3. ecshop里的$_CFG从哪来的

    以前经常有朋友问我, ecshop系统的$_CFG这个数组是从哪里来的,在哪里定义并赋值的.   下面就给大家说一下这个全局变量 $GLOBALS['_CFG']. ecshop里的 $_CFG数组主 ...

  4. java 导出excel(简单案例)

    public class Student { private int id; private String name; private int age; private Date birth; pub ...

  5. 浅析const标识符在C++函数的功能

    范例: class matrix { public: matrix(){}; const double getvalue(const unsigned row, const unsigned colu ...

  6. 6、Spring+Struts2+MyBatis(mybatis有代理)整合增删改查

    1.创建如下的oracle脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 c ...

  7. Leetcode 073 Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

  8. java innerclass

    ---恢复内容开始--- 内部类: public class Inner{ public class Inner2{} } 创建内部类对象 .new public class Test {    in ...

  9. JavaScript获取浏览器信息的方法

    Window有navigator对象让我们得知浏览器的全部信息.我们可以利用一系列的API函数得知浏览器的信息. JavaScript代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 1 ...

  10. 小飞淙在博客上的第一天——NOIP201505转圈游戏

    原本我是在word文档上写这种东西的,在杨老师的“强迫”下,我开始写了博客. 这是我在博客上的第一天,就先来个简单的,下面请看题: 试题描述  有n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时 ...