先整理出时间相关的程序,以后有空再写成单例。

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

最新文章

  1. 霍尼韦尔FC400A与FC400B的区别
  2. ngResource提交json数据如何带参数
  3. python 取两数的百分比
  4. 用通俗易懂的大白话讲解Map/Reduce原理
  5. java中DatagramSocket连续发送多个数据报包时产生丢包现象解决方案
  6. Word Frequency
  7. IOS学习之IOS沙盒(sandbox)机制和文件操作
  8. UVA 1594 Ducci Sequence(两极问题)
  9. 学习笔记DAY2
  10. spoj 10606 Balanced Numbers 数位dp
  11. 有关Gcd,Lcm的一点小结论
  12. cocos creator 碰撞检测
  13. liunx 下WebBench 安装与压力测试
  14. quartz相关记录
  15. 无预挖无ICO-潜力币XDAG最强攻略
  16. [bzoj1717][Milk Patterns 产奶的模式]
  17. python 断言大全
  18. Struts 框架
  19. WordPress-Word图片上传插件整合教程-Xproer.WordPaster
  20. linux内核完全剖析——基于0.12内核-笔记(1)-CPU 数据通信

热门文章

  1. maven项目ssh框架的整合
  2. 浏览器缓存(Web Cache/ Http Cache)
  3. linux用户的增加与删除
  4. socket概念 套接字
  5. 四、python小功能记录——按键转点击事件
  6. Nginx学习---企业级nginx环境搭建
  7. 使用普通用户set autotrace on报错SP2-0618: Cannot find the Session Identifier
  8. Git Hub 使用手册参考
  9. 荣禄[róng lù]
  10. iOS真机命令(自动化测试)