字符串转换成NSDate类型的 为nil解决方法
NSMutableString *timeString = [[NSMutableString alloc] initWithString:string];
[timeString setString:[timeString stringByReplacingOccurrencesOfString:@"/Date(" withString:@""]];
[timeString setString:[timeString stringByReplacingOccurrencesOfString:@")/" withString:@""]];
[timeString setString:[timeString substringToIndex:timeString.length - 3]];
return [NSDate dateWithTimeIntervalSince1970:[timeString longLongValue]];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:@"yyyyMMdd"];
[formatter1 setTimeZone:[NSTimeZone timeZoneWithName:@"GTM"]];//GTM,格林尼治时区
NSDate *date = [formatter1 dateFromString:time];
NSTimeInterval dateDiff = [date timeIntervalSinceNow];
int age= fabs(trunc(dateDiff / (60 * 60 * 24)) / 365);
转载于:https://www.cnblogs.com/tian-sun/p/4849762.html
字符串转换成NSDate类型的 为nil解决方法相关推荐
- mysql转换年月日_mysql中把字符串转换成日期类型:
mysql中把字符串转换成日期类型: select date_format('2013-03-09','%Y-%m-%d'); select date_format('2013-03-09','%y- ...
- 将字符串转换成String类型 eg:String s = “113@ ere qqq yyui“请输出所有子串【split方法】
package cn.meituan.homework;import java.util.Arrays;/*** String s = "113@ ere qqq yyui"请输出 ...
- 关于object转换成string类型出现错误的解决办法
如果map对象里的value值是object对象,获取object对象后,object对象强制转换成string,则有时候会出现报错: Exception in thread "main&q ...
- php使用json_decode后数字对象转换成了科学计数法的解决方法
解决方法:做了各方面的转换处理都不好使:$obj='{"order_id":213477815351175,"buyer":100001169269154}'; ...
- spring mvc使用@InitBinder 标签将日期格式字符串转换成Timestamp类型
在SpringMVC中,可以采用实体类来自动绑定表单传递过来的参数,但需要注意的是,若实体类属性是Date或Timestamp类型的话,SpringMVC将无法自动绑定,会产生400错误,所以需要我们 ...
- c++将字符串转换成 int 类型
#include<bits/stdc++.h> using namespace std;int main() {string str = "1233";int temp ...
- C#中字符串转换成枚举类型的方法
其中ActionType是枚举类型,"InListNext"是Actiontype类型的OnKeyUp的取值. (ActionType)Enum.Parse(typeof(Acti ...
- mysql中如何把字符串转换成日期类型
select date_format('2013-03-09','%Y-%m-%d'); select date_format('2013-03-09','%y-%m-%d');select STR_ ...
- 将时间格式的字符串转换成日期类型浏览器兼容解决方案
var currentTime = "20120612"; var y = currentTime.substring(0, 4); var m = currentTime.sub ...
最新文章
- 动手动脑课后实验性的问题
- Spring MVC系列[1]—— HelloWorld
- Vue 学习第四天 -2
- Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
- 用Java递增Map值的最有效方法–仅搜索一次键
- django使用mysql_设置Django以使用MySQL
- 学python买什么书-关于 Python 的经典入门书籍有哪些?(python三大经典书)
- AVCaptureDevice 属性介绍
- linux tcl expect 安装(转)
- 算法:获取链表的中间值Middle of the Linked List
- st8s003 c语言编译器,ST系列STM8S003F3P6单片机芯片介绍
- 图像加密标准测试图库
- 计算机win7系统还原,win7还原系统——win7系统还原出厂设置
- 2次拒领诺贝尔奖,爱迪生嫉妒他才华,被美国政府列为绝密人物
- 刚培训的java程序员怎么找工作,快来看鸭~
- 迅雷7 down.php,迅雷协议分析
- 普通话考试是从题库里抽吗_普通话考试试题有哪些
- 一文讲解电源技术中的安森美深力科NCP1680AAD1R2G CrM PFC控制器IC 详情讲解
- 详细了解 Linkerd 2.10 基础功能,一起步入 Service Mesh 微服务架构时代
- 百度云分享 vitis vivado 2021.1 2020.2 2020.1 2019.2 2019.1 2018.3 2018.2 2017.4 , all OS(win和linux)