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

}

最新文章

  1. *HDU1848 博弈
  2. 按要求编写Java应用程序。 (1)创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)、减速(车速自减)、修改车牌号,查询车的载重量。 编写两个构造方法:一个没有形参,在方法中将车牌号设置“XX1234”,速 度设置为100,载重量设置为100;另一个能为对象的所有属性赋值; (2)创建主类: 在主类中创建两个机动车对象。 创建第
  3. Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf path1-&gt;2-&gt;3which represents the number123. Find the total sum of a
  4. 短地址TinyURL的API使用
  5. Generic Data Access Layer泛型的数据访问层
  6. 兼容IE,Firefox,Opera等浏览器的添加到收藏夹js代码实现
  7. printf那点事
  8. vijos1080题解
  9. RabbitMQ 消息队列 入门 第一章
  10. 那些年我们一起踩过的Dubbo&quot;坑&quot;
  11. 洛谷P1144最短路计数题解
  12. [转] node.js下mongoose简单操作实例
  13. 对浏览器攻击:MS10-002
  14. LAMP搭建个人网站
  15. 贪吃蛇GamePanel Java实现(二)
  16. Linux 中 awk命令应用
  17. 认识和使用Task
  18. mysql主备部署[高可用]
  19. SUSE Linux Enterprise Server设置IP地址、网关、DNS(转载)
  20. PHP与Imagemagick

热门文章

  1. 第三章 Netty入门应用
  2. 本地Fiddler传递XML格式数据,调试微信功能。
  3. Java线程--interrupt join yield setDaemon常用方法的使用
  4. ESFramework ——可堪重任的网络通信框架
  5. intellij中javax包的导入
  6. NOIP2014-普及组复赛-第二题-比例简化
  7. unity 退到桌面的 OnApplicationPause
  8. iOS中控制器的释放问题
  9. jenkins 中集成JNI的坑
  10. NOIP2014提高组第二题联合权值