倒计时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>里面文字垂直显示
随机推荐
- 2016中国大数据技术大会( BDTC ) 共商大数据时代发展之计
中国大数据技术大会(BDTC)的前身是Hadoop中国云计算大会(HadoopinChina,HiC).从2008年仅60余人参加的技术沙龙发展到当下数千人的技术盛宴,目前已成为国内最具影响力.规模最 ...
- Spring Security(09)——Filter
目录 1.1 Filter顺序 1.2 添加Filter到FilterChain 1.3 DelegatingFilterProxy 1.4 FilterChainPr ...
- openwrt增加串口登录需要密码
https://wiki.openwrt.org/doc/howto/serial.console.password Openwrt 串口默认是没有密码的.Openwrt启动后,一个默认的密码将被启用 ...
- libmad编译
patch -Np1 -i ../libmad-0.15.1b-fixes-1.patch && sed "s@AM_CONFIG_HEADER@AC_CONFIG_HEAD ...
- ESFramework ——可堪重任的网络通信框架
ESFramework是一套性能卓越.稳定可靠.强大易用的跨平台通信框架,支持应用服务器集群.其内置了消息的收发与自定义处理(支持同步/异步模型).消息广播.P2P通道.文件传送(支持断点续传).心跳 ...
- LeetCode OJ 48. Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- BatteryWarning 电池预警
MTK BatteryWarning 在mediatek/external/batterywarning下,会编译生成一个可执行文件:batterywraning main()函数中,会间断读取 /s ...
- 调用CImg库显示WAV格式音频波形
最近在做傅里叶变换和小波变换时经常要通过显示波形来检验算法,但通过visual studio之类显示波形又显得麻烦,而且不能跨平台. CImg是一个跨平台的C++的图像处理库,提供的图像处理等功能十分 ...
- Spring 表单提交,后台自动封装有集合对象的对象
from表单: <form action="${pageContext.request.contextPath}/vote/save" method="post&q ...
- js 中null 和 undifined
1.一个重要问题 null == undifined (true) ; null === undefined (false) 为什么是这样的呢? undifined是未赋值的基本数据类型,未定义: n ...