[IOS] Timestamp and string time conversion __ios

Source: Internet
Author: User

[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;  }   


Related Article

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.