/** * Countdown * * @param endTime timestamp * * @return return time remaining */-(nsstring*) Remainingtimemethodaction: (Long Long) endtime{// Get current time NSDate *nowdata = [NSDate Date]; Convert timestamp to date format nsdate *enddata=[nsdate datewithtimeintervalsince1970:endtime]; Create a Calendar object nscalendar* Chineseclendar = [[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian] ; Set cell identity hour minute second day month year Nsuinteger unitflags = Nscalendarunithour | Nscalendarunitminute | Nscalendarunitsecond | Nscalendarunitday | Nscalendarunitmonth | Nscalendarunityear; Give the start time and end time to get the data for the identity of the unit nsdatecomponents *CPS = [Chineseclendar components:unitflags fromdate:nowdata Todate:enddata OPTIONS:0]; Nsinteger Hour = [cps Hour]; Nsinteger Min = [cps minute]; Nsinteger SEC = [cps second]; Nsinteger day = [CPS day]; Nsinteger Mon = [cps month]; Nsinteger year = [cps year]; NSLog (@ "From today to%@, Diff:years:%ld Months:%ld, Days;%ld, Hours:%ld, mins:%LD, Sec:%ld ", [nowdata description], year, Mon, Day, Hour, Min, sec); NSString *countdown = [NSString stringwithformat:@ "still left:%zi days%zi hours%zi minutes%zi seconds", Day,hour, Min, Sec]; if (sec<0) {countdown=[nsstring stringwithformat:@ "activity end/start snapping"]; } return countdown;}
IOS e-commerce shopping cart countdown time calculation