倒计时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>里面文字垂直显示
随机推荐
- HTTP Basic Authentication认证的各种语言 后台用的
访问需要HTTP Basic Authentication认证的资源的各种语言的实现 无聊想调用下嘀咕的api的时候,发现需要HTTP Basic Authentication,就看了下. 什么是HT ...
- 实验吧Web-天网管理系统
笔记 == : 比较运算符号 不会检查条件式的表达式的类型 ===: 恒等计算符 , 同时检查表达式的值与类型.(会检查表达式类型,如bool) PHP序列化与反序列化serialize() 对输 ...
- java 用双向链表实现SJBLinkedList
public class SJBLinkedList{ private Node first; private Node last; private int size; public int size ...
- GIAC全球互联网架构大会——互联网技术架构未来
GIAC全球互联网架构大会是高可用架构技术社区推出的面向架构师.技术负责人及高端技术从业人员的技术架构大会.中国拥有全球最大的互联网用户及移动互联网用户,如何使用合适的架构来搭建互联网系统,是每一个互 ...
- Codeforces Round #366 (Div. 2)_C. Thor
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- 二分法经典习题——HDU1969
#include <iostream>#include <cmath>#include <iomanip>using namespace std; double p ...
- openwrt启动过程(脚本)
来源: http://wiki.openwrt.org/doc/techref/preinit_mount#first.boot 基本的openwrt启动顺序为: 1.boot loader loa ...
- Lucene基础(2)
上一篇:Lucene基础(1) 一.Lucene术语 Document, Field, Term, Query, Analyzer相信在其中大多数在之前已经理解了...对其中部分概念详细说明 Docu ...
- Linux(power服务器)中kettle(2)
Hadoop集群硬件环境 4台机器 ip地址 172.16.1.131 172.16.1.132 172.16.1.133 172.16.1.134 每台内存16G 8核cpu 直接使用报错:
- 使 httpClient 支持中文
一个有效的方法:重载 PostMethod 的 getRequestCharSet 方法 1: class PostChinese { 2: HttpClient httpClient = new H ...