Conversion of time format

Source: Internet
Author: User

When the output time is in the format

Mon SEP 28 22:25:56 +0800 2015 If you want to display%@ seconds/minute/time before you need to format it

NSDateFormatter * formart=[[nsdateformatter alloc]init];

This sentence is for the simulator output is normal, and on the real machine when the output is empty

Nslocale * Local=[[nslocale alloc]initwithlocaleidentifier:@ "en_US"];

[Formart setlocale:local];

[Formart Setdateformat: @ "EEE MMM d HH:mm:ss zzz yyyy"];

nsdate * Date=[formart Datefromstring:li. Time];

Double inter=fabs([date Timeintervalsincenow]);

if (Inter < )

{

Cell. timelable. Text=[nsstring stringwithformat:@ "%.0lf seconds ago ", Inter];

}

Else if (Inter >&& Inter <60*)

{

Cell. timelable. Text=[nsstring stringwithformat:@ "%.0lf minutes ago ", inter/60 ];

}

Else if (Inter >60*&& Inter <60*60*)

{

Cell. timelable. Text=[nsstring stringwithformat:@ " today %@", Date];

}

Else

{

double i= inter/(24*60*);

Cell. timelable. Text=[nsstring stringwithformat:@ "%.0lf days ago ", I];

}

Conversion of time format

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.