NSString+TimeCategory
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>
NSString+TimeCategory的更多相关文章
- NSString属性什么时候用copy,什么时候用strong?
我们在声明一个NSString属性时,对于其内存相关特性,通常有两种选择(基于ARC环境):strong与copy.那这两者有什么区别呢?什么时候该用strong,什么时候该用copy呢 ...
- iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...
- 【去除NSString 字符串中的空格换行符】
@interface NSString (DeletWhiteSpace) // 返回一个去掉前后空格的字符串或者下划线,如果自己是一个nil 返回@“” - (NSString *)trimming ...
- NSString 的常用操作
NSString *testStr01=@"HelloWord"; NSString *testStr02=[testStr01 substringToIndex:];//取头(从 ...
- 时间戳转化为日期TimeStamp转NSDate转NSString
//时间戳处理 NSInteger time = [self.album.updatedAt integerValue] / 1000; NSNumber *timer = [NSNumber num ...
- iOS - Json解析精度丢失处理(NSString, Double, Float)
开发中处理处理价格金额问题, 后台经常返回float类型, 打印或转成NSString都会有精度丢失问题, 因此使用系统自带的NSDecimalNumber做处理, 能解决这问题:经过测试其实系统NS ...
- iOS NSString中的搜索方法rangeOfString
NSString *str = @"your://aaa?backscheme=my"; //在str中查找“backscheme=”,并返回一个NSRange类型的值,我们可以通 ...
- NSString相关操作
//创建一个字符串对象 NSString * str_1 = @"Hello"; //字面量方法 ; NSString * str_2 = [NSString stringWith ...
- NSString 和NSData 转换
NSString 转换成NSData 对象 NSData* xmlData =[@"testdata" dataUsingEncoding:NSUTF8StringEncoding ...
随机推荐
- ASP.NET页面执行顺序
原文地址:http://blog.csdn.net/a497785609/article/details/4510335 1.对象初始化(OnInit方法) 页面中的控件(包括页面本身)都是在它们最初 ...
- 无法打开包括文件:“SDKDDKVer.h”: No such file or directory
在已经装有Visual Studio 2010的系统中,同时安装Visual Studio 2012,安装过程很顺利,但到使用VS2013时,却出问题了. 本文主要介绍:VS中新建工程编译时出现,“无 ...
- Lightoj 1129【字典树】
题意:如果存在一个串是另一个串的公共前缀就是NO,否则就是YES 思路:利用字典树的特性搞搞就好了 #include <bits/stdc++.h> using namespace std ...
- HDU4791【杂】
题意: 给你一个从0开始的区间si,每个区间是前闭后开,[ s[i] , s[i+1] ), 然后再给你个一个pi,代表你在区间[ s[i] , s[i+1] )里面买东西的单价是pi,给出的s1一定 ...
- poj3276 Face The Right Way
Face The Right Way POJ - 3276 题目大意: n头牛排成一列,每头牛向前或向后,为了让所有牛都面向前方,设定一个k值,每操作一次恰好使k头连续的牛转向,求最少的操作次数m和对 ...
- IT兄弟连 JavaWeb教程 JSP语法
在JSP页面中,脚本标识使用的最为频繁,因为他们能够方便.灵活地生成页面中的动态内容,特别是JSP程序代码块.JSP中的脚本标识包括3部分,即JSP声明区.JSP表达式和JSP程序代码块.通过这些标识 ...
- 关于在linux系统环境下解压rar压缩文件
如果在zip压缩文件,可以使有unzip来进行解压.可以直接使用yum进行下载. 但如果是rar类型压缩文件,使用yum就可能无法直接安装. 要到网址:https://www.rarlab.com/d ...
- File upload in ASP.NET Core web API
参考1:File upload in ASP.NET Core web API https://www.janaks.com.np/file-upload-asp-net-core-web-api/ ...
- 几例实用的Shell脚本
日常工作中,经常编写一些shell命令或脚本以完成重复性操作,本文分享了最近用到的几例shell实用脚本. 1 特殊文件名的远程拷贝 服务器之间拷贝文件经常使用scp命令,其命令格式: (1)scp ...
- netty与MQ使用心得
最近在做分布式的系统,使用netty与mq进行远程RPC调用,现将心得经验总结一下. 我们公司的服务器在云端机房,在每一个店面有一个服务器,店面服务器外网无法访问. 我们的做法是店面服务器在启动时与云 ...