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