- 前段时间一直在和时间打交道,这几天整理了一下几个时间相互转换的方法,再次做记录
- 效果图
屏幕快照 2017-05-17 下午3.32.24.png
屏幕快照 2017-05-17 下午3.32.43.png
+(NSString *)timeStampConversionNSString:(NSString *)timeStamp
{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timeStamp longLongValue]/1000];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateStr = [formatter stringFromDate:date];
return dateStr;
}
+(NSString *)dateConversionTimeStamp:(NSDate *)date
{
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]*1000];
return timeSp;
}
+(NSDate *)nsstringConversionNSDate:(NSString *)dateStr
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *datestr = [dateFormatter dateFromString:dateStr];
return datestr;
}
网友评论