经常会遇到时间转换的,在此收藏一个时间换算的方法〜

 #pragma mark 时间换算

 + (NSString *)setcreateTime:(NSString *)str
{
//yyyy-MM-dd- HH:MMss"]; NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; //[formatter setDateStyle:NSDateFormatterMediumStyle]; //[formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"yyyy"]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CCT"]]; NSDate *date = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]]; NSString *dateStr = [formatter stringFromDate:date]; //本地时间
NSDate * senddate=[NSDate date];
NSDateFormatter * dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY"];
NSString * locationString=[dateformatter stringFromDate:senddate]; //[dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"]; //判断创建时间 与 本地时间 是否同一年
if ([dateStr isEqualToString:locationString]) {
[formatter setDateFormat:@"MM-dd HH:mm"];
}else{
[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
} date = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]];
dateStr = [formatter stringFromDate:date]; return [self compareCurrentTime:date :dateStr];
} + (NSString *) compareCurrentTime:(NSDate*) compareDate :(NSString *)str
{
NSTimeInterval timeInterval = [compareDate timeIntervalSinceNow];
timeInterval = -timeInterval;
long temp = ;
NSString *result;
if (timeInterval < ) {
if (timeInterval > ) {
result = [NSString stringWithFormat:@"%d秒前",(int)timeInterval+];
}else if (timeInterval < -){
result = str;
}
else{
result = [NSString stringWithFormat:@"%d秒前",];
} }
else if((temp = timeInterval/) <){
result = [NSString stringWithFormat:@"%ld分钟前",temp];
}else{
result = str;
} return result;
}

ios-时间换算的更多相关文章

  1. iOS时间问题

    在iOS开发中,经常会遇到各种各样的时间问题,8小时时差,时间戳,求时间间隔,农历等等.解决办法网上比比皆是,但大多零零散散,很多资料并没有说明其中问题.这里集中总结一下,以便于以后查阅和供大家参考. ...

  2. 程序设计入门——C语言 第2周编程练习 1时间换算(5分)

    1 时间换算(5分) 题目内容: UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8.现在,你的程序要读入一个整数,表示BJT的时和分.整数的个位和十位表示分,百位和千位表示小时.如果 ...

  3. 网易云课堂_程序设计入门-C语言_第二周:判断_1时间换算

    1 时间换算(5分) 题目内容: UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8.现在,你的程序要读入一个整数,表示BJT的时和分.整数的个位和十位表示分,百位和千位表示小时.如果 ...

  4. C++编程音视频库ffmpeg的pts时间换算方法

    ffmpeg中的pts,dts,duration时间记录都是基于timebase换算,我们主要分析下pts的时间怎么换算,其它的是一样的换算.ffmpeg的时间换算对许多新接触同学算是一个大坑,很多刚 ...

  5. Oracle时间换算:日,月,周数,星期,年

    http://blog.csdn.net/liangweiwei130/article/details/37930383 Oracle时间换算,留做记号!

  6. 中国大学MOOC-C程序设计(浙大翁恺)—— 时间换算

    时间换算(10分) 题目内容: UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8.现在,你的程序要读入一个整数,表示BJT的时和分.整数的个位和十位表示分,百位和千位表示小时.如果小 ...

  7. 中国MOOC_零基础学Java语言_第2周 判断_1时间换算

    第2周编程题 查看帮助 返回   第2周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨提示: 1.本次作业属于Online Judge题目,提交后由系统即时判分. 2.学生可以在作业截 ...

  8. iOS 时间的处理

    做App避免不了要和时间打交道,关于时间的处理,里面有不少门道,远不是一行API调用,获取当前系统时间这么简单.我们需要了解与时间相关的各种API之间的差别,再因场景而异去设计相应的机制. 时间的形式 ...

  9. iOS时间那点事儿–NSTimeZone

    NSTimeZone **时区是一个地理名字,是为了克服各个地区或国家之间在使用时间上的混乱. 基本概念: GMT 0:00 格林威治标准时间; UTC +00:00 校准的全球时间; CCD +08 ...

  10. iOS 时间处理(转)

    NSDate NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是NSDate的私有子类的实体. NSDate存储的是GMT时间,使用的时候会根据 当 ...

随机推荐

  1. MySQL行转列、列转行

    一.行转列 有如图所示的表,现在希望查询的结果将行转成列 建表语句如下: CREATE TABLE `TEST_TB_GRADE` ( `ID` int(10) NOT NULL AUTO_INCRE ...

  2. (2018 Multi-University Training Contest 2)Problem G - Naive Operations

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 题目大意:告诉你a,b两个数组,a数组初始化为0,b数组告诉你长度和具体值,接下来有q次操作,a ...

  3. Docker Toolbox

    Toolbox包含以下Docker工具: 用于运行docker-machine命令的Docker Machine 用于运行docker命令的Docker Engine Docker Compose用于 ...

  4. Jsの练习-数组常用方法 -forEach()

    forEach()  : 对数组进行遍历循环,对数组中的每一项运行给定函数. 格式: arr.forEach(function(value,index){}) <!DOCTYPE html> ...

  5. Object.assign的用法

    工作中使用的Object.assign 类的赋值 var initData = { a:'', b:'' } var oldData = { a:'ww', b:'ee' } var newData ...

  6. cv2.findContours

    Layout of the output array image is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] ...

  7. `TypeError: torch.mm received an invalid combination of arguments - got (torch.FloatTensor, Variable),

    `TypeError: torch.mm received an invalid combination of arguments - got (torch.FloatTensor, Variable ...

  8. spring对bean的高级装配之基于@Conditional条件化装配

    上篇介绍了如何基于profile来条件化创建bean,spring会根据profile的激活状态来进行创建;这篇介绍如何基于spring4.0引入的@Conditional和Condition接口来更 ...

  9. Exp0 Kali安装 Week1

    20165214 2018-2019-2 <网络对抗技术>Exp0 Kali安装 Week1 任务要求 Kali的下载.安装.共享.软件源. 步骤 1.从Kali的官网下载镜像文件.(直接 ...

  10. LXC vs Docker

    https://www.sumologic.com/blog/code/lxc-lxd-explaining-linux-containers/ see also: https://linuxcont ...