NSDate时间戳和时间相互转化
2016-06-07 12:26
357 查看
摘要: 时间戳和时间相互转化
时间戳 -->时间
- (NSString*)CalculateTimeWithStr:(NSString*)str{
NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
NSLog(@"date:%@",[detaildate description]);
//实例化一个NSDateFormatter对象
NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // EEEE -> 星期描述
y - year M- month d- day H- hour(24) h - hour(12) m - minute s - second
NSString *currentDateStr = [dateFormatter stringFromDate:detaildate];
return currentDateStr;
}
时间-->时间戳
NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
这个time就是现在时间的时间戳
时间戳 -->时间
- (NSString*)CalculateTimeWithStr:(NSString*)str{
NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
NSLog(@"date:%@",[detaildate description]);
//实例化一个NSDateFormatter对象
NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // EEEE -> 星期描述
y - year M- month d- day H- hour(24) h - hour(12) m - minute s - second
NSString *currentDateStr = [dateFormatter stringFromDate:detaildate];
return currentDateStr;
}
时间-->时间戳
NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
这个time就是现在时间的时间戳
相关文章推荐
- SQL Server时间戳功能与用法详解
- sqlite时间戳转时间语句(时间转时间戳)
- PHP时间戳使用实例代码
- jquery中实现时间戳与日期相互转换
- 把时间戳转换为日期格式的js代码
- 时间戳转换为时间 年月日时间的JS函数
- php strtotime 函数UNIX时间戳
- php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
- 使用php 获取时间今天明天昨天时间戳的详解
- 时间处理函数工具分享(时间戳计算)
- Python时间戳与时间字符串互相转换实例代码
- js获取时间并实现字符串和时间戳之间的转换
- js处理php输出时间戳对不上号的解决方法
- mysql时间戳转成常用可读时间格式的两种方法
- MySQL中日期和时间戳互相转换的函数和方法
- javascript获取当前的时间戳的方法汇总
- javascript时间戳和日期字符串相互转换代码(超简单)
- php上传图片之时间戳命名(保存路径)
- PHP 返回13位时间戳的实现代码
- 时间戳与时间相互转换(php .net精确到毫秒)