OC时间戳转时间方法系列
// 时间戳转时间
+ (NSString *)timeStampConv:(NSString *)timestamp;
// 秒转换成00:00:00
+ (NSString *)timeSecConv:(NSString *)second;
// 字符串转时间
+ (NSDate *)stringToDate:(NSString *)dateString withDateFormat:(NSString *)format;
// 时区转换
+ (NSDate *)worldTimeToChinaTime:(NSDate *)date;
// 时间转时间戳
+ (NSString *)timeConvStamp:(NSString *)time;
+(NSString *)timeStampConv:(NSString *)timestamp{
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timestamp integerValue]];
//NSTimeZone *zone = [NSTimeZone systemTimeZone]; //时区偏移
//NSInteger interval = [zone secondsFromGMTForDate:confromTimesp];
//NSDate *localeDate = [confromTimesp dateByAddingTimeInterval: interval];
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
return [dateFormat stringFromDate:confromTimesp];
}
+ (NSString *)timeSecConv:(NSString *)second{
NSInteger hours=[second integerValue]/3600;
NSInteger minutes=([second integerValue]-hours*3600)/60;
NSInteger seconds=[second integerValue]-hours*3600-minutes*60;
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours,(long)minutes,(long)seconds];
}
+ (NSDate *)stringToDate:(NSString *)dateString withDateFormat:(NSString *)format
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];
NSDate *date = [dateFormatter dateFromString:dateString];
return date; //[JZanFunc worldTimeToChinaTime:date];
}
+ (NSDate *)worldTimeToChinaTime:(NSDate *)date
{
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
NSInteger interval = [timeZone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval:interval];
return localeDate;
}
+ (NSString *)timeConvStamp:(NSString *)time{
NSDate* date = [JZanFunc stringToDate:time withDateFormat:@"yyyy-MM-dd HH:mm"];
NSTimeInterval a=[date timeIntervalSince1970]; // *1000 是精确到毫秒,不乘就是精确到秒
NSString *timeString = [NSString stringWithFormat:@"%.0f", a]; //转为字符型
return timeString;
}