iOS:时间相关(18-10-13更)
先整理出时间相关的程序,以后有空再写成单例。
1、日历(NSCalendar)
2、时间格式()
3、时间戳
附录:
1、定时器
1、日历(NSCalendar)
1、想要获取 世纪、年、月、日、时、分、秒、星期 等信息,需要加入对应的枚举。
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
NSUInteger units = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
2、时间格式()
3、时间戳
附录:
1、定时器
1)、使用方法
//定时1秒,重复
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; //定时中断处理
-(void)timerAction:(NSTimer*)timer
{
NSArray *viewArray = timer.userInfo;
} //定时器失效、释放
[timer invalidate];
补充:理论上,多个任务挂载到同一个定时器上,在定时中断处理,判断某任务是否需要暂停。
而不是,每个任务添加一个定时器,然后暂定定时器来暂停任务。
2)、滚动视图,定时器失效。解决方法:添加到RunLoop里
// NSDefaultRunLoopMode - 标准优先级
// NSRunLoopCommonModes - 高优先级
// UITrackingRunLoopMode - 用于 UIScrollView 和别的控件的动画 timer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) { }]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
补充:NSDefaultRunLoopMode ,默认模式,使用该模式还是会失效。
UITrackingRunLoopMode,用这个模式跟UIScrollView相同模式,拖动可以正常计时。
NSRunLoopCommonModes,把timer同时添加到上面两种RunLoop模式下(网上写的),拖动可以正常计时。
// 获得当前线程的 RunLoop 对象
[NSRunLoop currentRunLoop];
// 获得主线程的 RunLoop 对象
[NSRunLoop mainRunLoop];
iOS:时间相关(18-10-13更)的更多相关文章
- App适配iPhone 6/ Plus和iOS 8:10条小秘诀
App适配iPhone 6/ Plus和iOS 8:10条小秘诀 iPhone 6iOS 8适配 (原文:raywenderlich 作者:Jack Wu 译者:@TurtleFromMars ...
- macOS 10.13 High Sierra odoo11 开发配置--完整版
1.抹盘安装macOS Sierra 10.13: 制作macOS安装启动盘参见:http://www.iplaysoft.com/macos-usb-install-drive.html 2.安装g ...
- Ubuntu 18.10 版本发布
Ubuntu 是一个基于 Debian 的以桌面为主的 Linux 发行版,以其应用性而闻名.Ubuntu 提供三种官方版本:用于个人计算机的 Ubuntu 桌面,用于服务器和云的 Ubuntu 服务 ...
- win7笔记本VirtualBox安装黑苹果MacOS 10.13
环境 时间:2018.04.09,没有指明时间的教程都是耍流氓 笔记本:某州优雅A460P-i7G D2,4G内存,Intel Core i7-2670QM四核八线程(老笔记本勉强能用),ssd硬盘, ...
- 黑苹果之DELL台式机安装Mac OS X 10.13.6版本操作系统
由于本人所在的公司一般都是DELL的品牌台式机,所以以DELL台式机做小白鼠.记得在2012年的时候,在当时的那家公司为了学习自学IOS开发的Objective-C开发语言的时候,由于囊中羞涩买不起m ...
- 从Ubuntu 18.04 LTS升级到Ubuntu 18.10版本的方法
从Ubuntu 18.04 LTS升级到Ubuntu 18.10版本的方法 2018-10-18 21:08:39作者:ywnz稿源:云网牛站 本文提供从Ubuntu 18.04 LTS(Bionic ...
- 解决 Ubuntu 18.10 使用较新的独立显卡输出无法初始化图形界面并配置深度学习开发环境
原文地址:解决 Ubuntu 18.10 使用较新的独立显卡输出无法初始化图形界面并配置深度学习开发环境 0x00 配置 硬件 OS: Ubuntu 18.10 Base Board: ASUS WS ...
- 背水一战 Windows 10 (13) - 绘图: Stroke, Brush
[源码下载] 背水一战 Windows 10 (13) - 绘图: Stroke, Brush 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Stroke - 笔划 Brush ...
- [CareerCup] 18.10 Word Transform 单词转换
18.10 Given two words of equal length that are in a dictionary, write a method to transform one word ...
- macOs升级到10.13.1Beta || JAVA升级到最新版之后PhpStorm菜单栏问题
macOs升级到10.13.1Beta || JAVA升级到最新版之后PhpStorm菜单栏会消失,估计不止出现在PhpStorm,一系列jetbrains的产品可能都会有这个问题,包括eclipis ...
随机推荐
- laravel之路由汇总
- android 获取http请求json数据
package com.my.gethttpjsondata; import java.io.BufferedReader;import java.io.ByteArrayOutputStream;i ...
- C语言四舍五入算法
对h进行四舍五入 1. 网络上搜索来的: C语言取整规则: (int)(h + 0.5) 2. 二级教程: 四舍五入并精确到小数点后面的第n位: 实例:
- 第十五章——自编码器(Autoencoders)
自编码器是一种能够通过无监督学习,学到输入数据高效表示的人工神经网络.输入数据的这一高效表示称为编码(codings),其维度一般远小于输入数据,使得自编码器可用于降维(查看第八章).更重要的是,自编 ...
- 算法之杨辉三角形(Java语言)
杨辉三角形, 又称贾宪三角形.帕斯卡三角形. 前9层写出来如下: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 ...
- 小程序UI
从input组件说起 <input maxlength="10" placeholder="最大输入长度10" /> <div id=&quo ...
- 没有对比就没有伤害,memcache and redis
Memcached 与 Redis 的关键性能指标比较 性能对比: Redis 只使用单核,而 Memcached 可以使用多核,所以平均每一个核上 Redis在存储小数据时比 Memcached 性 ...
- Mysql进阶-day2
Mysql cmake方式安装 1.卸载原有mysql下载MySQL安装包 [root@localhost ~]# yum remove mysql* -y [root@localhost ~]# m ...
- LNMP-day1-安装并配置
Nginx安装 #Nginx [root@localhost downloads]# pwd /root/downloads #安装依赖pcre [root@localhost downloads]# ...
- MapReduce Design Patterns(chapter 2 (part 3))(四)
Inverted Index Summarizations Pattern Description 反向索引模式在MapReduce分析中经常作为一个例子.我们将会讨论我们要创建的term跟标识符之间 ...