The constructor converts the timestamp to a few just/hours ago/a few days ago/a few years ago
Createtimestring 13-bit pure digital time stamp for backstage.
-(NSString *) Updatetimeforrow: (NSString *) createtimestring {//Get current time stamp 1466386762.345715 10-bit integer 6 decimal
Nstimeinterval currenttime = [[NSDate date] timeIntervalSince1970];
Create a song timestamp (the time returned in the background is typically 13 digits)
Nstimeinterval createtime = [createtimestring longlongvalue]/1000;
Time
Nstimeinterval time = Currenttime-createtime;
Nsinteger sec = time/60;
if (sec<60) {
return [NSString stringwithformat:@ "%ld minutes Ago", sec];
}
Second Turn hour
Nsinteger hours = time/3600;
if (hours<24) {
return [NSString stringwithformat:@ "%ld hours ago", hours];
}
Seconds to turn days
Nsinteger days = time/3600/24;
if (days < 30) {
return [NSString stringwithformat:@ "%ld day Ago", days];
}
Second Turn month
Nsinteger months = TIME/3600/24/30;
if (months < 12) {
return [NSString stringwithformat:@ "%ld months ago", months];
}
Seconds following year
Nsinteger years = TIME/3600/24/30/12;
return [NSString stringwithformat:@ "%ld years ago", years];
}
Appendix: If the background gives the time format is: Yyyy-mm-dd HH:mm:ss. Sss
+ (NSString *) Comparecurrenttime: (NSString *) str {//convert string to nsdate nsdateformatter *dateformatter = [[Nsdateforma
Tter alloc] init]; [Dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss.
SSS "];
NSDate *timedate = [Dateformatter datefromstring:str];
Get with the current time difference nstimeinterval timeinterval = [Timedate Timeintervalsincenow];
TimeInterval =-timeinterval;
Standard Time and Beijing 8-hour lag timeinterval = timeinterval-8*60*60;
Long temp = 0;
NSString *result;
if (TimeInterval <) {result = [NSString stringwithformat:@ "just"];
else if (temp = timeinterval/60) <60 {result = [NSString stringwithformat:@ "%d minutes ago", temp];
else if (temp = temp/60) <24 {result = [NSString stringwithformat:@ "%d hours ago", temp];
else if ((temp = temp/24) <30) {result = [NSString stringwithformat:@ '%d days ago ', temp];
else if (temp = temp/30) <12 {result = [NSString stringwithformat:@ '%d months ago ', temp];
} else{temp = TEMP/12;
result = [NSString stringwithformat:@ "%d years ago", temp];
return result; }