博客
关于我
Object c将一个double值转换为时间格式
阅读量:798 次
发布时间:2023-02-17

本文共 734 字,大约阅读时间需要 2 分钟。

在平时的学习中,我总会把一些小技巧积攒起来,满足自己的收藏癖好。虽然古董收藏比敲代码更适合我,但可惜没有钱买古董,于是只能继续写代码了。以下是一段代码示例:

#####//返回当前时间的时间戳 ##double timeStamp = [[NSDate date] timeIntervalSince1970];;

#####//NSTimeInterval 时间间隔,double类型 ##NSTimeInterval time = timeStamp;

#####//得到Date类型的时间,这个时间是1970-1-1 00:00:00经过你时间戳的秒数之后的时间 ##NSDate * detaildate = [NSDate dateWithTimeIntervalSince1970:time];;

#####//实例化NSDateFormatter对象 ##NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];;

#####//设定时间格式,以下是示例设置 ##[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];;

#####//转换成字符串 ##NSString * currentDateStr = [dateFormatter stringFromDate:detaildate];;

#####//输出一下 ##NSLog(@"%@", currentDateStr);;

然后我就拿着这个字符串去开心地赋值了……

转载自:https://juejin.im/post/5cb467885188251b14579cac

你可能感兴趣的文章
Objective-C实现hanning 窗(附完整源码)
查看>>
Objective-C实现hanoiTower汉诺塔算法(附完整源码)
查看>>
Objective-C实现hardy ramanujana定理算法(附完整源码)
查看>>
Objective-C实现harmonic series调和级数算法(附完整源码)
查看>>
Objective-C实现harris算法(附完整源码)
查看>>
Objective-C实现HashTable哈希表算法(附完整源码)
查看>>
Objective-C实现haversine distance斜距算法(附完整源码)
查看>>
Objective-C实现heap sort堆排序算法(附完整源码)
查看>>
Objective-C实现heaps algorithm堆算法(附完整源码)
查看>>
Objective-C实现heap堆算法(附完整源码)
查看>>
Objective-C实现Heap堆算法(附完整源码)
查看>>
Objective-C实现hexagonal numbers六边形数算法(附完整源码)
查看>>
Objective-C实现hidden layers neural network浅层神经网络算法(附完整源码)
查看>>
Objective-C实现highest response ratio next高响应比优先调度算法(附完整源码)
查看>>
Objective-C实现hill climbing爬山法用来寻找函数的最大值算法(附完整源码)
查看>>
Objective-C实现Hill密码加解密算法(附完整源码)
查看>>
Objective-C实现histogram stretch直方图拉伸算法(附完整源码)
查看>>
Objective-C实现Hopcroft算法(附完整源码)
查看>>
Objective-C实现horizontal projectile motion平抛运动算法(附完整源码)
查看>>
Objective-C实现hornerMethod霍纳法算法(附完整源码)
查看>>