IOS local time, UTC time, timestamp, and more

Source: Internet
Author: User
Tags local time

//获得当前时间并且转为字符串
-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.