LYMTimeTool

作者: Mg明明就是你 | 来源:发表于2016-08-29 23:00 被阅读67次
  • 主要运用场景:音频和视频播放的时间 (由此来转换)

LYMTimeTool.h

//  LYMTimeTool.h
//  05-QQ
//
//  Created by ming on 15/11/24.
//  Copyright © 2015年 ming. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface LYMTimeTool : NSObject


/**
 *  整型转化字符串
 *  eg:153秒 -> 02:33
 *
 *  program: 返回 02:33 这种类型的字符串
 */
+ (NSString *)getFormatTimeWithTimeInterval:(NSInteger)timeInterval;


/**
 *  字符串转化整型
 *  eg:02:33 -> 153秒
 *
 *  program: 返回 153秒 这种类型的整型
 */
+ (float)getTimeIntervalWithFormatTime:(NSString *)format;

@end```
***

#LYMTimeTool.m

//
// LYMTimeTool.m
// 05-QQ音乐
//
// Created by ming on 15/11/24.
// Copyright © 2015年 ming. All rights reserved.
//

import "LYMTimeTool.h"

@implementation LYMTimeTool

/**

  • 整型转化字符串
  • eg:153秒 -> 02:33
  • program: 返回 02:33 这种类型的字符串
    */
  • (NSString *)getFormatTimeWithTimeInterval:(NSInteger)timeInterval{
    NSInteger sec = (NSInteger)timeInterval % 60;
    NSInteger min = (NSInteger)timeInterval / 60;

    return [NSString stringWithFormat:@"%02zd:%02zd",min,sec];
    }

/**

  • 字符串转化整型
  • eg:02:33 -> 153秒
  • program: 返回 153秒 这种类型的整型
    */
  • (float)getTimeIntervalWithFormatTime:(NSString *)format{
    // NSArray *minsec = [format componentsSeparatedByString:@":"];
    // NSString min = [minsec firstObject];
    // NSString sec = [minsec lastObject];
    // return min.intValue
    60 + sec.floatValue
    0.01;
    NSArray *minAsec = [format componentsSeparatedByString:@":"];
    NSString *min = [minAsec firstObject];
    NSString *sec = [minAsec lastObject];

    return min.intValue * 60 + sec.floatValue;
    }

@end

相关文章

  • LYMTimeTool

    主要运用场景:音频和视频播放的时间 (由此来转换) LYMTimeTool.h //// LYMTimeToo...

网友评论

    本文标题: LYMTimeTool

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