// Select * from 'date'; Class func timeDoubleTimeString(date:NSDate)->(String){let localeDate = NSDate() /// Date to time let timeDouble:Double = fabs(localeDate.timeIntervalSinceDate(date)) let time = Int(timeDouble) if time<60{return "\(time) seconds ago "} if time<60*60{return "\(time/60 *60) min ago "} if time<60*60*24{return "\(time/(60*60)) hours ago "}  let dateFormat = NSDateFormatter() dateFormat.dateFormat = "MM-dd HH:mm"//yyyy-MM-dd HH:mm:ss" return dateFormat.stringFromDate(date) }Copy the code

/ * *

  • Time conversion part

// How many seconds have passed since 1970 -(NSString *)getTimeSp {NSString *time; NSDate *fromdate=[NSDate date]; time = [NSString stringWithFormat:@”%f”,[fromdate timeIntervalSince1970]]; return time; }

-(NSDate)changeSpToTime:(NSString)spString {NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString intValue]]; NSLog(@”%@”,confromTimesp); return confromTimesp; }

// Convert the timestamp to NSDate, plus the time zone offset. After this conversion is Beijing time -(NSDate*)zoneChange:(NSString*)spString {NSDate* confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString intValue]]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interval = [zone secondsFromGMTForDate:confromTimesp]; NSDate *localeDate = [confromTimesp dateByAddingTimeInterval: interval]; NSLog(@”%@”,localeDate); return localeDate; }

-(long)timeDifference:(NSDate *)date {NSDate *localeDate = [NSDate date]; long difference =fabs([localeDate timeIntervalSinceDate:date]); return difference; }

-(NSString*)nsdateToString:(NSDate *)date {NSDateFormatter dateFormat=[[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSString string=[dateFormat stringFromDate:date]; NSLog(@”%@”,string); return string; }