倒计时demo
#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的更多相关文章
- unity3d之简单的时钟倒计时demo
输入结束时间,开始倒计时,时间差不超过一天,附上代码:(关于个位数显示,加个判断如果小于10 显示的字符串加上0) using System.Collections; using System.Col ...
- js倒计时demo 天/时/分/秒
<html><head> <meta charset="UTF-8"> <title>js简单时分秒倒计时</title> ...
- html—倒计时demo
<!doctype html> <html> <head> <meta charset="utf-8"> </head> ...
- 倒计时的js实现 倒计时 js Jquery
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=987 一.如火如荼的团 ...
- 倒计时(jQuery)
倒计时,在网页制作中会经常用到,特别是一些节日活动页面运用更是广泛.今天就和大家分享一下jQuery如何实现倒计时.话不多说,言归正传,倒计时开始: 首先,既然是用jQuery实现,那么前提就是要先引 ...
- js实现倒计时 类似团购网站
一.demo与效果展示 为节约时间,我就直接套用了企鹅团的界面作为demo的背景.因为是倒计时,所以需要一个固定的时间,为了n年后,某位仁兄打开demo页面依然在倒计时,所以我把倒计时时间设成了205 ...
- js 发送短信倒计时、秒杀倒计时实现代码
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- Android倒计时功能的实现
Android中的倒计时的功能(也能够直接使用CountDownTimer这个类直接实现,相关此Demo可查看我的博客).參考了网上写的非常好的一个倒计时Demo: watermark/2/text/ ...
- vue 倒计时返回首页
1. vue页面15分钟无操作时返回首页 2. 基于vue的倒计时demo 3. 在vue2.0项目中一个简单的倒计时功能 4. vue重新发送验证码 5. 表格<td>里面文字垂直显示
随机推荐
- Partial Tree
Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是 ...
- 【LeetCode】434. Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- visual studio2013 改变匹配括号的颜色
改变匹配括号的颜色实现如下效果
- php基本(四)表单验证
本文内容来自http://www.w3school.com.cn/php/php_form_url_email.asp PHP 表单验证 - 验证 E-mail 和 URL 本节展示如何验证名字.电邮 ...
- MySQL数据类型和属性
日期和时间数据类型 MySQL数据类型 含义 date 3字节,日期,格式:2014-09-18 time 3字节,时间,格式:08:42:30 datetime 8字节,日期时间,格式:2014-0 ...
- kettle连接mysql
kettle连接mysql时出现问题
- UVALive 6672 Bonus Cards 概率dp
题意呢 就是有两种售票方式 一种是icpc 一种是其他方式 icpc抢票成功的概率是其他方式的2倍…… 这时 一个人出现了 他通过内幕知道了两种抢票方式各有多少人 他想知道自己如果用icpc抢票成功的 ...
- MBProgressHUD详解
1,MBProgressHUD常用属性和用法Demo - (void)testMBProgressHUD { NSLog(@"test MBProgressHUD "); /* 要 ...
- 杭电20题 Human Gene Functions
Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...
- li浮动时ul高度为0,解决ul自适应高度的几种方法
网址:http://www.gxchina.com/edu/11208.html 1.给ul元素设置高度height最直接的办法是给ul元素设置一个高度,即ul标签添加height属性,代码如下: u ...