IOS获取时间戳并转化为对应格式的时间
来源:互联网 发布:哥本哈根会议 知乎 编辑:程序博客网 时间:2024/06/05 16:57
//获取时间戳 NSTimeInterval time = [[NSDate date] timeIntervalSince1970]; //转换成标准时间 NSDate * detaildate=[NSDate dateWithTimeIntervalSince1970:time]; //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //设定时间格式,这里可以设置成自己需要的格式 NSString *currentDateStr; //获取完整的时间 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.TotalTime.text = currentDateStr; //获取年份 [dateFormatter setDateFormat:@"yyyy"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Year.text = currentDateStr; //获取月份 [dateFormatter setDateFormat:@"MM"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Month.text = currentDateStr; //获取天 [dateFormatter setDateFormat:@"dd"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Day.text = currentDateStr; //获取24小时制的小时 [dateFormatter setDateFormat:@"HH"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Hour24.text = currentDateStr; //获取12小时制的小时 [dateFormatter setDateFormat:@"hh"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Hour12.text = currentDateStr; //获取分 [dateFormatter setDateFormat:@"mm"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Minute.text = currentDateStr; //获取秒 [dateFormatter setDateFormat:@"ss"]; currentDateStr = [dateFormatter stringFromDate: detaildate]; self.Second.text = currentDateStr;
demo下载地址:http://download.csdn.net/detail/linyang24/9332837
0 0
- IOS获取时间戳并转化为对应格式的时间
- java中获取不同时间格式的方法!及时间戳转化为时间格式
- IOS笔记:获取当前时间,并转化为一定格式字符串
- iOS日常需求:将服务器时间戳转化为自己需要的时间格式
- Java 时间戳转化为时间格式
- 时间戳转化为时间格式
- 时间戳转化为时间格式
- IOS如何将获取的13位时间戳转化为标准时间
- iOS将时间转化为时间戳
- c# 获得网络时间(GMT格式)并转化为本地时间的方法
- perl 字符串格式转化为时间格式,时间戳,epchotime
- PHP 时间戳转化为日期格式
- 时间戳字符串转化为date格式
- 时间戳转化为日期格式
- 获取系统时间及将时间戳转化为时间
- json传出的时间戳转化为标准格式
- iOS开发之时间格式的转化
- iOS开发中时间格式的转化
- c++_3: 继承和组合
- 栈溢出利用--预备知识
- 触发器
- android中src和background区别
- “解决问题”与“消灭问题”
- IOS获取时间戳并转化为对应格式的时间
- PSI_SI
- Python语言assert用法
- LeetCode 100:Same Tree
- jsp获取websocket的远程服务器地址
- 引路蜂Android游戏编程教程
- ANDROID.JAVA常用参考资料网址
- 两个栈实现队列 两个队列实现栈
- CSS学习<7>