-(NSString *) timewithtimeintervalstring: (NSString *) timestring{//format Timensdateformatter* formatter =[[NSDateFormatter alloc] init]; Formatter.timezone= [Nstimezone timezonewithname:@"Shanghai"]; [Formatter Setdatestyle:nsdateformattermediumstyle]; [Formatter Settimestyle:nsdateformattershortstyle]; [Formatter Setdateformat:@"yyyy mm month DD Day hh:mm"]; //millisecond value converted to secondsnsdate* date = [NSDate datewithtimeintervalsince1970:[timestring doublevalue]/1000.0]; NSString* DateString =[Formatter stringfromdate:date]; returndatestring;} Time conversion to timestamp//Current Timensdate* date = [NSDate Datewithtimeintervalsincenow:0]; Nstimeinterval a=[date timeintervalsince1970]* +;//*1000 is accurate to milliseconds, no multiplication is accurate to secondsNSString *timestring = [NSString stringWithFormat:@"%.0f", a];//convert to character typemethod of returning month and day by comparing time with current time- (void) Getbabydetailage: (NSString *) date{//Get Date ObjectNSDateFormatter *formatter_ =[[NSDateFormatter alloc] init]; Formatter_.dateformat=@"YYYY-MM-DD HH:mm:ss"; NSDate*createdate =[Formatter_ datefromstring:date]; Nscalendar*gregorian =[[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian]; Nsuinteger Unitflags= Nscalendarunitday | Nscalendarunitmonth |nscalendarunityear; Nsdatecomponents*components = [Gregorian components:unitflags fromdate:createdate todate:[nsdate Date] Options:0 ]; Nsinteger years=[Components of year ]; Nsinteger months=[Components Month]; Nsinteger Days=[Components day];}
Issues with IOS timestamps