OC时间格式化字符串

作者: Bug集 | 来源:发表于2015-10-29 21:33 被阅读650次

http://potter528.bj.bdysite.com

/**
 *  将时间秒数格式化为字符串
 *
 *  @param second 秒数
 *
 *  @return 返回字符串
 */
+ (NSString *)getStringFormatBySeconds:(float) second{
    
    //格式化时间,从浮点型类型转化成"00:00"字符串
    NSString *formattTime = [NSString stringWithFormat:@"%02d:%02d",(int)second / 60,(int)second % 60];
    return formattTime;
}
/**
 *   将字符串格式化为时间秒数
 *
 *  @param timeString 时间字符串
 *
 *  @return 返回float
 */
+(float)getSecondsFormatByStrings:(NSString *)timeString{
    
    NSArray *tempArray = [timeString componentsSeparatedByString:@":"];
    
    
    return [[tempArray firstObject] integerValue] * 60.0 + [[tempArray lastObject] intValue];
}

相关文章

  • OC三大基础类常用汇总

    字符串 String 初始化定义 字符串中把c字符串转成oc字符串 将其他类型格式化转为oc字符串类型的功能 不可...

  • Swift基础 - 字符串

    简单拼接 字符串遍历 字符串长度 格式化字符串 Swift字符串与OC中字符串对比 Swift中是String类型...

  • 常用方法

    时间类 时间格式化 时间计算 字符串 字符串截取 数字格式化 axios拦截器

  • OC时间格式化字符串

    http://potter528.bj.bdysite.com

  • MySQL日期、字符串、时间戳互转

    一、时间格式化为字符串 二、时间转时间戳 三、字符串转时间 四、字符串转时间戳 五、时间戳转时间 六、时间戳格式化...

  • Swift 之字符串

    字符串的长度 字符串的拼接 字符串的格式化 字符串的子串 知道 as 的作用 - 类似于 OC 中的类型转换在 S...

  • 03.对象操作

    字符串的声明 在OC中,用NSString类声明的字符串时一个对象 用@创建字符串 创建一个格式化的字符串 字符串...

  • iOS时间格式化、时间戳、日期格式化、常见格式互转

    1)当前时间格式化---转字符串 2)当前时间格式化---转时间戳(13位) 3)时间戳(13位)---转字符串 ...

  • swift 基本认识

    1,格式化创建字符串 2,数组 array(跟 OC 里面的数组是可以互相转换的) 3,字典 dictionary...

  • python之time模块2

    时间 格式化 使用 time.strftime() 函数 可以格式化输出时间 时间转字符串 : time.strf...

网友评论

    本文标题:OC时间格式化字符串

    本文链接:https://www.haomeiwen.com/subject/uykfhttx.html