NSString+TimeCategory.h
//------------------------------------------------
#import <foundation foundation.h=""> @interface NSString (TimeCategory)
+ (NSString *)stringWithTime:(NSTimeInterval)time;
- (NSTimeInterval)timeValue; @end
//------------------------------------------------
//NSString+TimeCategory.m
//------------------------------------------------
#import "NSString+TimeCategory.h" @implementation NSString (TimeCategory) + (NSString *)stringWithTime:(NSTimeInterval)time {
BOOL isPositive;
NSInteger timeInt; if (time > * || time < - * )
return nil;
if (time < ) {
timeInt = (NSInteger)-time;
isPositive = NO;
} else {
timeInt = (NSInteger)time;
isPositive = YES;
} NSInteger hour = timeInt/;
NSInteger minute = (timeInt%)/;
NSInteger second = (timeInt%)%; if (hour > ) {
if (isPositive) {
return [NSString stringWithFormat:@"%d%d:%d%d:%d%d",
hour/, hour%, minute/, minute%, second/, second%];
} else {
return [NSString stringWithFormat:@"-%d%d:%d%d:%d%d",
hour/, hour%, minute/, minute%, second/, second%];
} } else {
if (isPositive) {
return [NSString stringWithFormat:@"%d%d:%d%d", minute/, minute%, second/, second%];
} else {
return [NSString stringWithFormat:@"-%d%d:%d%d", minute/, minute%, second/, second%];
} }
} - (NSTimeInterval)timeValue {
NSInteger hour = , minute = , second = ;
NSArray *sections = [self componentsSeparatedByString:@":"];
NSInteger count = [sections count];
second = [[sections objectAtIndex:count - ] integerValue];
minute = [[sections objectAtIndex:count - ] integerValue];
if (count > ) {
hour = [[sections objectAtIndex:] integerValue];
}
return hour * + minute * + second;
} @end
</foundation>

最新文章

  1. 《图解TCP/IP》读书笔记
  2. Azure Backup (2) Azure备份服务
  3. cygwin 安装apt-cyg命令
  4. phpstrom正则替换
  5. nlssort函数的用法以及参数
  6. adb操作命令详解及大全
  7. ES6的promise对象研究
  8. R语言 rwordseg包的下载
  9. ionic 项目的启动屏幕
  10. thinkphp 前后版本ajaxReturn方法的分别
  11. CGI与FastCGI 转
  12. [RxJS] Getting Input Text with Map
  13. Ubuntu 定时任务中的环境变量设置
  14. 通过mysqlbinlog 恢复数据
  15. mysql 实现 sqlserver的row_number over() 方法
  16. 记录js new Date日期处理的一个坑
  17. Jeecg-Boot Spring Boot
  18. C#对象内部属性排序测试
  19. 基础006_pg109_IP-Xfft
  20. CS229 6.15 Neurons Networks Deep Belief Networks

热门文章

  1. Linux Ctrl+Z的使用方法
  2. C语言--递归问题
  3. CF-831B
  4. HDOJ-1391
  5. 20个Flutter实例视频教程-第08节: 保持页面状态
  6. jquery快速入门三
  7. LeetCode: 448 Find All Numbers Disappeared in an Array(easy)
  8. Cookie和Session(3)
  9. 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解
  10. Linux下配置 禅道 (项目管理系统)