- (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
// 格式化时间
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"]; // 毫秒值转化为秒
NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0];
NSString* dateString = [formatter stringFromDate:date];
return dateString;
}
时间转化为时间戳 // 当前时间
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:];
NSTimeInterval a=[date timeIntervalSince1970]*; // *1000 是精确到毫秒,不乘就是精确到秒
NSString *timeString = [NSString stringWithFormat:@"%.0f", a]; //转为字符型
通过比较时间与当前时间返回年月日的方法
- (void)getBabyDetailAge:(NSString *)date
{
// 获得日期对象
NSDateFormatter *formatter_ = [[NSDateFormatter alloc] init];
formatter_.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *createDate = [formatter_ dateFromString:date]; NSCalendar *gregorian = [[ NSCalendar alloc ] initWithCalendarIdentifier : NSCalendarIdentifierGregorian];
NSUInteger unitFlags = NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear;
NSDateComponents *components = [gregorian components:unitFlags fromDate:createDate toDate:[NSDate date] options: ]; NSInteger years = [components year];
NSInteger months = [components month ];
NSInteger days = [components day ];
}

iOS 时间戳的问题的更多相关文章

  1. iOS 时间戳的转换

    在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理.例如: //实例化一个NSDateFormatter对象 NSDateForma ...

  2. iOS 时间戳

    时间戳用过一回,总结一下: 1.在Terminal下获得时间戳: date +%s 原来要在服务器端挂文档,方便开发商下载,用时间戳作为文件名称来区分. 2.在程序下获得时间戳: NSDate * n ...

  3. IOS时间戳

    什么是时间戳? 时间戳(timestamp),通常是一个字符序列,唯一地标识某一刻的时间.数字时间戳技术是数字签名技术一种变种的应用. 思考:简单来讲就是根据文件hash加密后生成的摘要和时间生成的时 ...

  4. iOS 时间戳转换为时间

    NSString *str=";//时间戳 NSTimeInterval time=[str doubleValue]+;//因为时差问题要加8小时 == 28800 sec NSDate ...

  5. iOS 时间戳和时间互换,计算两日期相隔天数

    /*  *获取当前系统时间的时间戳  */ +(NSInteger)getNowTimestamp;   /**  * 获取当前时间  */ + (NSString *)getNowTimeTampF ...

  6. iOS 时间戳转成今天,上午,下午,星期几,几月几日,某年某月某日

    项目中有聊天功能,老板让聊天的时间转换成和 QQ 的聊天时间一样的格式, 研究了一下,来分析下 QQ 的聊天格式时间 代码: 会话列表显示的时间 如需转成24小时制,需要使用 HH //时间显示内容 ...

  7. ios 时间戳 当前时间 相互转化

    1.今天在做一个webservice的接口的时候,被要求传一个时间戳过去,然后就是开始在Google上找 2.遇到两个问题,一,当前时间转化为时间戳,二,获取的当前时间和系统的时间相差8个小时 一,转 ...

  8. iOS标准时间与时间戳相互转换

    iOS标准时间与时间戳相互转换 (2012-07-18 17:03:34) 转载▼ 标签: ios 时间戳 标准时间 格式 设置 转化 杂谈 分类: iPhone开发 设置时间显示格式:     NS ...

  9. iOS开发时间戳与时间NSDate,时区的转换,汉字与UTF8,16进制的转换

    http://blog.sina.com.cn/s/blog_68661bd80101njdo.html 标签: ios时间戳 ios开发时间戳 ios16进制转中文 ios开发utf8转中文 ios ...

随机推荐

  1. Postman使用教程学习笔记

    刚加入网页测试行列,最近在学习POSTman的使用教程,记录下学习笔记. Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件.当开发人员需要调试一个网页是否运行正常,并不是 ...

  2. unity笔录

    ----------------------------unity项目在启动splash的时候黑屏 原因不明------------------测试复制项目  用剔除法测试 笔录开始 先用原版本打包 ...

  3. PyCharm 安装指南

    一.官网下载最新版的PyCharm,根据平台选择版本(Liunx,Windows) 地址:https://www.jetbrains.com/pycharm/download/#section=win ...

  4. 解决larave-dompdf中文字体显示问题

    1.安装laravel-dompdf依赖. Packagist:https://packagist.org/packages/barryvdh/laravel-dompdf composer requ ...

  5. eclipse 使用问题

    eclipse 启动失败,错误信息为org.eclipse.swt.SWTException: Failed to execute runnable 方法三:删除了workspace\.metadat ...

  6. SNS

    SNS,专指社交网络服务.也指社交现有已成熟普及的信息载体,如短信SMS服务.SNS的另一种常用解释:全称Social Network Site,即“社交网站”或“社交网”.SNS也指Social N ...

  7. javaWEB总结(11):JSP简介及原理

    前言 本文主要通过一个简单小例子,介绍JSP的原理. 1.项目结构 2.web.xml <?xml version="1.0" encoding="UTF-8&qu ...

  8. PHP全角半角转换函数

    之前试过网上找的通过ASCII之类的字符替换,发现很多莫名其妙的问题.最后还是换成下面的字符替换方式了,把目前能找到的所有全角都列出来了一个个替换吧 /** * 全角字符转换为半角 * * @para ...

  9. Memory and Scores

    Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...

  10. L2-007. 家庭房产

    L2-007. 家庭房产 题目链接:https://www.patest.cn/contests/gplt/L2-007 并查集 初学,看这题的时候完全没有什么好的想法,参考了@yinzm的blog用 ...