时间戳转字符串,单独写了一个类方法。转换方便。
2016-11-12 10:17
190 查看
类方法:
//时间戳转字符串
+(NSString *)getTimeString:(long int)time;
//时间戳转字符串
+(NSString *)getTimeString:(long int)time
{
NSTimeInterval timeInterval = time + 28800;
NSDate * date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString * dateStr = [dateFormatter stringFromDate:date];
return dateStr;
}
//时间戳转字符串
+(NSString *)getTimeString:(long int)time;
//时间戳转字符串
+(NSString *)getTimeString:(long int)time
{
NSTimeInterval timeInterval = time + 28800;
NSDate * date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString * dateStr = [dateFormatter stringFromDate:date];
return dateStr;
}
相关文章推荐
- js中使用eval()方法将字符串转换成日期格式、并获取指定时间的日期
- java时间戳与日期字符串相互转换方法
- time_t tm timeval 和 时间字符串的转换方法
- Linux C/C++时间字符串与time_t之间的转换方法(转)
- C语言中时间戳转换成时间字符串的方法
- mysql中字符串和时间互相转换的方法(自动转换及DATE_FORMAT函数)
- 时间DateTime类型转换为字符串String格式方法汇总
- C++ Builder 字符串时间格式转换为TDateTime方法
- java--时间字符串类型转换为可存入数据库时间类型的方法
- 方法 时间字符串 转换
- 字符串转换时间的方法
- js 字符串与数值相互转换,以及时间戳转换成日期形式字符串方法
- 时间日期转换为字符串String类型及常用的方法
- Linux C/C++时间字符串与time_t之间的转换方法(转)
- js时间戳对象和标准格式字符串之间的转换方法
- Java日期时间字符串和毫秒相互转换的方法
- js方法将系统当前时间转换为字符串
- JS中字符串转换为日期对象的方法JS中如何计算时间,如何比较时间
- python时间戳于时间格式字符串相互转换的方法