- (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. hibernate中的sql语句

    hibernate的hql查询语句总结   在这里通过定义了三个类,Special.Classroom.Student来做测试,Special与Classroom是一对多,Classroom与Stud ...

  2. iOS 最新App提交上架流程及部分问题的解决方案2016.12.21,感谢原博主!!!

    内容摘自http://www.cocoachina.com/bbs/3g/read.php?tid=330302,原博特别详细,下面我对部分地方进行了修改,主要是对在打包验证和上传的时候遇到的问题进行 ...

  3. winform开线程,避免页面假死

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. 前端学习 html

    Html 前端学习 <!DOCTYPE html> < lang="en"> <head> <meta charset="UTF ...

  5. jquery如何获取url中问号后面的数值

    假如路径是这样的:www.domain.com/list/?menu=1 var locationUrl = location.search.substring(6); switch(location ...

  6. python join()阻塞的用法

    join()阻塞的用法,用来检测线程有没有完全执行完毕 #!/usr/bin/env python#-*- coding:utf-8 -*-import threadingimport time de ...

  7. Oracle获取时间日期月份星期数

    1.日期和字符转换函数用法(to_date,to_char)select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual; ...

  8. C# WebBrowser禁止F5刷新

    在用写一个桌面软件的过程中,用到webbrowser实现界面.这时有一个禁止webbrowser通过f5按键进行刷新的要求.本着边做边学的原则,本菜查了一下百度,原来这么简单,代码如下: this.w ...

  9. Paxos算法简单介绍

    一种基于消息传递且具有高度容错特性的一致性算法.解决在存在宕机或者网络异常的集群中对某个数据的值达成一致性,并且保证无论在发生以上任何异常都不会破坏整个系统的一致性,具有容错性. Paxos算法实现的 ...

  10. ZZNU 1995: cots' times

    题目描述 XX年XX月XX日小cot学会了回文数,eg:121. 小cot上课容易走神, 经常看看这个,瞧瞧那个.在小cot某一次走神的过程中他发现电子表上的时间也有回文数... 当然,并不是每次走神 ...