//获得当前时间并且转为字符串
-(NSString *) datetransformtotimestring{NSDate*currentdate = [NSDate Date];//get the current time to UTC time 2014-07-16 07:54:36 UTC (UTC time is 8 hours longer than the standard difference)//Convert to StringNSDATEFORMATTER*DF = [[NSDateFormatter alloc]init];//instantiating a time format class[DF Setdateformat:@"YYYY-MM-DD HH:mm:ss"];//Formatting//2014-07-16 07:54:36 (NSString Class)NSString *timestring =[DF Stringfromdate:currentdate]; returntimestring;}
< Span class= "hljs-built_in" >< Span class= "hljs-built_in" >< Span class= "hljs-comment" >// Get current time to timestamp
-(NSString *) datetransformtotimesp{ = [[NSDate date] timeintervalsince1970]*; Client Current 13-bit millisecond timestamp nsstring *timesp = [NSString stringWithFormat:@ "%llu" , Recordtime]; // Timestamp-to- string (13-bit millisecond timestamp string) return Timesp;}
1 //Timestamp string 1469193006001 (ms) 1469193006.001 (MS, 1469193006001234 (microseconds) 1469193006.001234 (μs) to UTC time 2016-08-11t07:0 0:55.611z2-(NSString *) Timesptoutcformat: (NSString *) Timesp3 {4NSString *timestring = [Timesp stringbyreplacingoccurrencesofstring:@"."Withstring:@""];5 if(Timestring.length >=Ten) {6NSString *second = [timestring substringtoindex:Ten];7NSString *milliscond = [timestring substringfromindex:Ten];8NSString * timestampstring = [NSString stringWithFormat:@"%@.%@", Second,milliscond];9Nstimeinterval _interval=[timestampstring Doublevalue];TenNSDate *date =[NSDate Datewithtimeintervalsince1970:_interval]; One ANSDateFormatter *dateformatter =[[NSDateFormatter alloc] init]; -Nstimezone *timezone = [Nstimezone timezonewithname:@"UTC"]; - [Dateformatter Settimezone:timezone]; the[Dateformatter Setdateformat:@"yyyy-mm-dd ' T ' HH:mm:ss. SSS ' Z '"]; -NSString *datestring =[Dateformatter stringfromdate:date]; - - returndatestring; + } - return @""; +}
< Span class= "hljs-string" >//13 bit timestamp 1469193006001 (ms) rpm System time 2016-08-11 08:55:36
1+ (NSString *) Timesptoymdformat: (NSNumber *) Timesp2 {3NSString *stime =[Timesp stringvalue];4Nstimeinterval time = [[Stime substringtoindex:Ten] Doublevalue];5NSDate *detaildate=[NSDate datewithtimeintervalsince1970:time];6NSDateFormatter *dateformatter =[[NSDateFormatter alloc] init];7[Dateformatter Setdateformat:@"YYYY-MM-DD HH:mm:ss"];8 9 return[Dateformatter stringfromdate:detaildate];Ten}
< Span class= "hljs-built_in" > < Span class= "Hljs-number" >< Span class= "hljs-built_in" >// Time-to-timestamp method: Senddate for NSDate class
NSString *timesp = [NSString stringWithFormat:@ '%ld', (long) [senddate TIMEINTERVALSINCE1970]];
< Span class= "hljs-built_in" > < Span class= "Hljs-number" >< Span class= "hljs-built_in" >
IOS local time, UTC time, timestamp, and so on