//nsstring* timestr = [self stringwithdate: [nsdate dateWithTimeIntervalSince1970 : usergifgrouptentity. Lastgiftsenttime / + ]]
-(nsstring *) Stringwithdate: ( NSDate *) Date {
if (date = = nil)
return @ "";
nsdate *now = [nsdate date];
nstimeinterval time = [ now timeintervalsincedate:d ate];
nscalendar* calendar = [nscalendar Currentcalendar ];
nsdatecomponents *nowcomponents = [Calendar components: Nsyearcalendarunit | Nshourcalendarunit fromdate: now];
nsdatecomponents *datecomponets = [Calendar components: Nsyearcalendarunit fromdate:d ate];
nsdateformatter *dateformatter = [[nsdateformatter alloc ] init];
[dateformatter Setcalendar: [nscalendar Autoupdatingcurrentcalendar]];
if ([nowcomponents year]! = [Datecomponets year] c23>]) {
[dateformatter setdateformat:@ "mm-dd-yyyy"];
return [dateformatter stringfromdate:d ate];
}
int nowhour = (int) [Nowcomponents hour ];
int Days_ago = ((int) time + 3600* ( Nowhour))/(3600*);
if (Days_ago = = 0) {
[dateformatter setdateformat:@ "hh:mm"];
return [dateformatter stringfromdate:d ate];
}else if(Days_ago = = 1) {
return @ "Yesterday";
}else{
[dateformatter setdateformat:@ "MM-DD"];
return [dateformatter stringfromdate:d ate];
}
}
Convert iOS time class to String