博客
关于我
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

你可能感兴趣的文章
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>
node.js 怎么新建一个站点端口
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
node.js 配置首页打开页面
查看>>
node.js+react写的一个登录注册 demo测试
查看>>
Node.js中环境变量process.env详解
查看>>
Node.js安装与配置指南:轻松启航您的JavaScript服务器之旅
查看>>
Node.js的循环与异步问题
查看>>
nodejs libararies
查看>>
nodejs npm常用命令
查看>>
nodejs 运行CMD命令
查看>>