[IOS] timestamp vs. String time conversion
Timestamp of the current time + (NSString *) cnowtimestamp{nsdate *newdate = [NSDate Date];
long int timesp = (long) [Newdate timeIntervalSince1970];
NSString *temptime = [NSString stringwithformat:@ "%ld", Timesp];
return temptime; }//timestamp--String time + (nsstring *) Cstringfromtimestamp: (nsstring *) timestamp{ Methods of //time stamping nsdate *timedata = [nsdate dateWithTimeIntervalSince1970:[timestamp intValue]]; nsdateformatter *dateformatter =[[nsdateformatter alloc] init]; [dateformatter setdateformat:@ "yyyy year mm month DD Day hh:mm"]; nsstring *strtime = [dateformatter stringfromdate:timedata]; return strTime; } //String time--timestamp + (nsstring *) Ctimestampfromstring: (nsstring *) thetime{ //thetime __@ "%04d-%02d-%02d %02d:%02d:00" //for timestamp NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setdateformat:@ "Yyyy-mm-dd hh:mm:ss"]; // nstimezone* timezone = [nstimezone timezonewithname:@ "Asia/ Beijing "]; // [formatter setTimeZone:timeZone]; nsdate* datetodo = [formatter datefromstring:thetime]; nsstring *timesp = [nsstring stringwithformat:
@ "%ld", (long) [datetodo timeintervalsince1970]];
return timeSp; }