以毫秒为整数值的时间戳转换

  • 时间戳转化为时间NSDate
- (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:0];
NSTimeInterval a=[date timeIntervalSince1970]*1000; // *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: 0 ]; NSInteger years = [components year];
NSInteger months = [components month ];
NSInteger days = [components day ];
}

iOS 时间和时间戳之间转化的更多相关文章

  1. js时间和时间戳之间如何转换(汇总)

    js时间和时间戳之间如何转换(汇总) 一.总结 一句话总结: 1.js中通过new Date()来获取时间对象, 2.这个时间对象可以通过getTime()方法获取时间戳, 3.也可以通过getYea ...

  2. python—时间与时间戳之间的转换

    python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...

  3. python 时间和时间戳的转化

    时间戳与时间之间的转换,需要一个中间过程,即将先将时间或时间戳先转为时间元组! 1.时间转时间戳: import datetime, time s = datetime.datetime(2016,6 ...

  4. 【python-时间戳】时间与时间戳之间的转换

    对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块,具体的操作有如下的几种: 将时间转换 ...

  5. python 时间与时间戳之间的转换

    https://blog.csdn.net/kl28978113/article/details/79271518 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运 ...

  6. js时间与时间戳之间的转换操作,返回天、小时、分,全家桶

    1.将时间戳转换成时间 var formatDate = function(d) {  var now = new Date(d); var year = now.getFullYear(); var ...

  7. python——时间与时间戳之间的转换

    http://blog.csdn.net/google19890102/article/details/51355282

  8. iOS开发NSDate、NSString、时间戳之间的转化

    //将UTCDate(世界标准时间)转化为当地时区的标准Date(钟表显示的时间) //NSDate *date = [NSDate date]; 2018-03-27 06:54:41 +0000 ...

  9. utc时间、本地时间及时间戳转化

    1.时间戳的概念 时间戳的定义请看百科unix时间戳,需要注意的时间戳为当前时刻减去UTC时间(1970.1.1)零点时刻的秒数差,与当前系统所处的时区无关,同一时刻不管在任何时区下得到的时间戳都是一 ...

随机推荐

  1. 让Linq的OrderBy支持动态字段

    使用linq的OrderBy,如果明确知道是哪个字段,当然很容易: IQueryable<User> userQuery = ...; userQuery.OrderBy(u => ...

  2. android锁屏软件制作

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/mingyue_1128/article/details/33726515 转载请标明出处http:/ ...

  3. HR-部门内部调动报表

    *&---------------------------------------------------------------------* *& Report  ZHRPA038 ...

  4. C语言中string char int类型转换

    C语言中string -- ::) 转载 ▼ 标签: 操作符 int char c语言 类型转换 分类: C/Cpp ,char型数字转换为int型 "; printf(]-');//输出结 ...

  5. P4284 [SHOI2014]概率充电器 dp

    这个题题干说的不清楚,一开始我以为只能是旁边紧挨着的传火,导致我一开始根本不知道哪错了.后来,我想到树形dp,但是需要正反考虑,()既要考虑父亲,又要考虑儿子),互相都有影响,所以没太想出来.后来知道 ...

  6. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

  7. bzoj1426 (洛谷P4550) 收集邮票——期望

    题目:https://www.luogu.org/problemnew/show/P4550 推式子……:https://blog.csdn.net/pygbingshen/article/detai ...

  8. python编写猜拳代码

    一.项目要求: 电脑随机出拳和用户猜拳三次.胜利条件如下: (1)(石头 胜 剪刀) (2)(剪刀 胜 布) (3)(布 胜 石头) 二.代码 #!/usr/bin/env python # -*- ...

  9. r.json()

    requests模块中,r.json()为Requests中内置的JSON解码器 其中只有response返回为json格式时,用r.json()打印出响应的内容, 如果response返回不为jso ...

  10. Ajax 异步查询 ,刷新页面的一部分

    调用的过程是,通过Jquery注册单击事件,当单击分部视图中的按钮,就取得分部视图中文本框的值,然后调用$.Get()函数以Get形式调用控制器SearchPeople方法,参数为searchText ...