#pragmaMark-Gets the current timestamp-(NSString *) gettimesp{NSDate* dat = [nsdate datewithtimeintervalsincenow:0]; //returns the------12 of the 13-bit timestamp *1000Nstimeinterval A=[dat timeintervalsince1970]* +; NSString*timestring = [NSString stringWithFormat:@"%f", a];//convert to character type returntimestring;}#pragmaMark-time to get the current YYYY-MM-DD HH:mm:ss format-(NSString *) gettime{NSDate*fromdate=[NSDate Date]; NSDateFormatter*dateformat=[[NSDateFormatter alloc]init]; [DateFormat Setdateformat:@"YYYY-MM-DD HH:mm:ss"]; NSString*string=[DateFormat stringfromdate:fromdate]; return string;}#pragmaMark-Convert time in YYYY-MM-DD HH:mm:ss format to timestamp/** * TIMESTR:YYYY-MM-DD time in HH:MM:SS format*/-(Long) Changetimetotimesp: (NSString *) timestr{LongTime ; NSDateFormatter*format=[[NSDateFormatter alloc] init]; [Format Setdateformat:@"YYYY-MM-DD HH:mm:ss"]; NSDate*fromdate=[format DATEFROMSTRING:TIMESTR]; time= (Long) [FromDate timeIntervalSince1970]; returnTime ;}#pragmaMark-time to convert timestamp to YYYY-MM-DD HH:MM:SS format/** * TIMESTR:10/13 digit timestamp*/-(NSString *) Changetimesptotime: (NSString *) timestr{unsignedLong LongCreatetime; if(Timestr.length = =Ten){ //10-bit timestampCreatetime =[Timestr Longlongvalue]; }Else{ //13-bit timestampCreatetime = [Timestr Longlongvalue]/1000.0; } nsdate*creatdate =[[NSDate alloc] initwithtimeintervalsince1970:createtime]; NSDateFormatter*creatdateformatter =[[NSDateFormatter alloc] init]; Creatdateformatter.dateformat=@"YYYY-MM-DD HH:mm:ss"; NSString*ordertimeend =[Creatdateformatter stringfromdate:creatdate]; returnordertimeend;}
IOS Time Conversion