Ios-oc gets the current state of the distance based on the timestamp (just, minutes ago, today, yesterday)
Get time stamp
- -(NSString *) Distancetimewithbeforetime: (Double) Betime
- {
- Nstimeinterval now = [[nsdatedate]timeintervalsince1970];
- double distancetime = now-betime;
- NSString * DISTANCESTR;
- nsdate * bedate = [nsdatedatewithtimeintervalsince1970:betime];
- NSDateFormatter * df = [[Nsdateformatteralloc]init];
- [DF Setdateformat:@ "hh:mm"];
- NSString * timestr = [df stringfromdate:bedate];
- [DF Setdateformat:@ "DD"];
- NSString * nowday = [DF stringfromdate:[nsdate Date]];
- NSString * Lastday = [df stringfromdate:bedate];
- if (Distancetime < 60) {//less than one minute
- Distancestr = @ "just";
- }
- Else if (Distancetime <60*60) {//time less than one hour
- DISTANCESTR = [NSString stringwithformat:@ "%ld minutes Ago", (long) distancetime/60];
- }
- Else if (Distancetime <260*60 && [Nowdayintegervalue] = = [Lastday IntegerValue]) {//time less than one day
- DISTANCESTR = [NSString stringwithformat:@ "Today%@", TIMESTR];
- }
- Else if (distancetime<260*60*2 && [nowdayintegervalue]! = [Lastday IntegerValue]) {
- if ([Nowday IntegerValue]-[Lastday integervalue] = =1 | | ([Lastday IntegerValue]-[Nowdayintegervalue] > 10 && [nowdayintegervalue] = = 1)) {
- DISTANCESTR = [NSString stringwithformat:@ "Yesterday%@", TIMESTR];
- }
- else{
- [DF Setdateformat:@ "Mm-dd hh:mm"];
- DISTANCESTR = [DF stringfromdate:bedate];
- }
- }
- Else if (Distancetime <260*60*365) {
- [DF Setdateformat:@ "Mm-dd hh:mm"];
- DISTANCESTR = [DF stringfromdate:bedate];
- }
- else{
- [DF Setdateformat:@ "Yyyy-mm-dd hh:mm"];
- DISTANCESTR = [DF stringfromdate:bedate];
- }
- return distancestr;
- }
Ios-oc gets the current state of the distance based on the timestamp (just, minutes ago, today, yesterday)