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的更多相关文章

  1. NSString属性什么时候用copy,什么时候用strong?

           我们在声明一个NSString属性时,对于其内存相关特性,通常有两种选择(基于ARC环境):strong与copy.那这两者有什么区别呢?什么时候该用strong,什么时候该用copy呢 ...

  2. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  3. 【去除NSString 字符串中的空格换行符】

    @interface NSString (DeletWhiteSpace) // 返回一个去掉前后空格的字符串或者下划线,如果自己是一个nil 返回@“” - (NSString *)trimming ...

  4. NSString 的常用操作

    NSString *testStr01=@"HelloWord"; NSString *testStr02=[testStr01 substringToIndex:];//取头(从 ...

  5. 时间戳转化为日期TimeStamp转NSDate转NSString

    //时间戳处理 NSInteger time = [self.album.updatedAt integerValue] / 1000; NSNumber *timer = [NSNumber num ...

  6. iOS - Json解析精度丢失处理(NSString, Double, Float)

    开发中处理处理价格金额问题, 后台经常返回float类型, 打印或转成NSString都会有精度丢失问题, 因此使用系统自带的NSDecimalNumber做处理, 能解决这问题:经过测试其实系统NS ...

  7. iOS NSString中的搜索方法rangeOfString

    NSString *str = @"your://aaa?backscheme=my"; //在str中查找“backscheme=”,并返回一个NSRange类型的值,我们可以通 ...

  8. NSString相关操作

    //创建一个字符串对象 NSString * str_1 = @"Hello"; //字面量方法 ; NSString * str_2 = [NSString stringWith ...

  9. NSString 和NSData 转换

    NSString 转换成NSData 对象 NSData* xmlData =[@"testdata" dataUsingEncoding:NSUTF8StringEncoding ...

随机推荐

  1. 关于window.event.srcElement 和 window.event.target(触发事件的对象)

    转自:https://www.cnblogs.com/zhilingege/p/7423817.html window.event.srcElement   是指触发事件的对象 <script ...

  2. mfc画波形函数

    void CMyPicoTestDlg::DrawWave(CDC *pDC,CRect &rectPicture) { float fDeltaX; float fDeltaY; int n ...

  3. Android开发技巧--引用另一个工程

    现在已经有了一个Android工程A.我们想扩展A的功能,但是不想在A的基础上做开发,于是新建了另外一个Android工程B,想在B中引用A. 1:把工程A做成纯Jar包,这样其他的工程就可以直接引用 ...

  4. 2-1Java简介

    java程序执行流程 java平台:

  5. Identity Server 4 原理和实战(完结)_----选看 OAuth 2.0 简介(上)

    https://www.yuque.com/yuejiangliu/dotnet/cg95ni 代表资源所有者的凭据 授权 Authorization Grant 授权是一个代表着资源所有者权限的凭据 ...

  6. maven:mirrors和repository的关系区别

    原文地址:http://my.oschina.NET/sunchp/blog/100634 1 Repository(仓库) 1.1 Maven仓库主要有2种: remote repository:相 ...

  7. python-os.walk()使用举例

    文件目录结构 dir 1 1 1.txt 2.txt 3.txt 2 2.txt 3 4 4.txt 3.txt 1.txt 2 2.txt 3 3.txt dir.txt 代码: import os ...

  8. 1004 Counting Leaves (30 分)

    A family hierarchy is usually presented by a pedigree tree. Your job is to count those family member ...

  9. POJ3696【欧拉函数+欧拉定理】

    题意: 求最小T,满足L的倍数且都由8组成,求长度: 思路: 很强势的福利:点 图片拿出去食用更优 //#include<bits/stdc++.h> #include<cstdio ...

  10. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...