iOS digital time and time conversion

Source: Internet
Author: User

The digital time stamp and the time mutual grasping exchange

Note: Because Java is more accurate than PHP time, so, the time of the background data Java is 13 bits, and PHP is 10 bits, iOS time to scratch only support 10 digits, so if the Java writing backstage, the number/1000 on the line. The following are the specific procedures:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    Formatter.dateformat = @ "Yyyy-mm-dd HH:mm:ss";
    NSDate *date = [[NSDate alloc] init];
   NSString *datestr = [formatter stringfromdate:date];
    NSLog (@ "%@", datestr);
    Time is converted to digital timestamp/*
    -(Nstimeinterval) Timeintervalsincedate: (NSDate *) anotherdate;
     @property (readonly) nstimeinterval Timeintervalsincenow;
     @property (readonly) nstimeinterval timeIntervalSince1970;
     * *
    Nsinteger numtime = date.timeintervalsince1970;
    NSString *numtimestr = [NSString stringwithformat:@ "%ld", Numtime];
    NSLog (@ "%@", numtimestr);
    The digital time is converted to a timestamp, if it is 13 digits divided by 1000, or after 3 digits are removed
    nsdate *date2 = [NSDate datewithtimeintervalsince1970:numtime];
    NSString *DATESTR2 = [formatter stringfromdate:date2];
    NSLog (@ "%@", DATESTR2);


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.