NSDate class summary, comprehensive basis, nsdate summary basis

Source: Internet
Author: User
Tags date1

NSDate class summary, comprehensive basis, nsdate summary basis

<Span style = "font-size: 24px;"> <span style = "font-size: 18px;"> // 1. create date object // The NSDate object created will always be zero time zone. If you want to calculate the time zone in GMT, add eight hours NSDate * date = [NSDate date]; NSLog (@ "% @", date); // create the date at this time tomorrow (the time interval is calculated in seconds) NSDate * tomorrow = [NSDate dateWithTimeIntervalSinceNow: 24*60*60]; NSLog (@ "% @", tomorrow); // create the date at the time of yesterday (-indicates that the start date is counted from the current time) NSDate * yesterday = [NSDate dateWithTimeIntervalSinceNow:-24*60*60]; NSLog (@ "% @", yesterday ); // obtain the time interval between two dates (timeInterval is a redefinition of the Double Precision type, so the output time must be % g, and the time price is calculated in seconds) NSTimeInterval timeInterval = [tomorrow timeIntervalSinceDate: yesterday]; NSLog (@ "% g", timeInterval/60/60/24); // compare the morning and evening of a date // (1) compare the earlier dates of the two dates (Return Value Type: NSDate) NSDate * earlerDate = [yesterday earlierDate: tomorrow]; NSLog (@ "% @", earlerDate); // (2) compare the date NSDate * laterDate = [yesterday laterDate: tomorrow]; NSLog (@ "% @", laterDate); // (3) compare two dates (the return value type is Enumeration type, which is to take the first parameter to subtract the value of the second parameter, the enumerated value is-, 1) NSComparisonResult result = [yesterday compare: tomorrow]; NSLog (@ "% ld", result); // time interval exercise: If a fixed time is less than 60 seconds, output "just ", if "60-3600" is output "how many minutes ago", if "3600-3600*24" is output "how many hours ago ", if the number of days before the output is greater than 3600*24, NSDate * date1 = [NSDate date]; NSDate * date2 = [NSDate dateWithTimeIntervalSinceNow: 100]; NSTimeInterval time = [date2 timeIntervalSinceDate: date1]; if (time> 0 & time <= 60) {NSLog (@ "just");} else if (time <= 3600) {NSLog (@ "% d Minutes Ago", (int) (time/60);} else if (time <= 3600*24) {NSLog (@ "% d Hours Ago", (int) (time/60/60);} else {NSLog (@ "% d days ago", (int) (time/60/60/24);} // NSDateFormatter Date Format class // function: convert a date into a string in a certain format ), you can also convert the date format string to the NSDate object NSDate * date3 = [NSDate date]; // create the current date object NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; // create Date Format object [formatter setDateFormat: @ "yyyy-MM-dd HH: mm: SS"]; // set the date format for the object. // specify the date format. // HH indicates the 24-hour format. hh indicates the 12-hour format. // MM indicates the month. mm indicates the minute. // dd indicates the number of days in the month. DD indicates the day of the current year. // ss indicates the number of seconds. // If the year is set to two yy, only the last two digits of the year are displayed. If y is given to another number, the complete year is displayed. // For example, if MM and so on are given two digits, if the month is one digit, the first digit is 0. [formatter setDateStyle: NSDateFormatterFullStyle]; // set the date output style [formatter setTimeStyle: NSDateFormatterFullStyle]; // set the time output style NSString * dateStr = [formatter stringFromDate: date3]; NSLog (@ "% @", dateStr); // convert the date format string to an NSDate object @ "20:08:08" NSString * dateStr1 = @ "2008-08-08 20:08:08 "; // create date formatter NSDateFormatter * formatter1 = [[NSDateFormatter alloc] init]; // set the date format (must be consistent with the date format in the Date Format String ). [formatter1 setDateFormat: @ "yyyy-MM-dd HH: mm: ss"]; // convert the format string to NSData object NSDate * date4 = [formatter1 dateFromString: dateStr1]; NSLog (@ "% @", date4); </span>


Summary of basic biology knowledge in high school (Comprehensive)

I can only help you in this way. You should answer questions first, wait for your score to reach 200 points, and then offer a 200 reward. Then, let the experts help you to sum up the question. In this way, the hope is higher.

Who has the basic knowledge of object-c?

You can directly purchase a book-based recommendation <object-c basic tutorial>
More than 300 pages can be viewed in two or three days

I will not summarize the basic knowledge. I will summarize it only if I do not understand it (NO)
 

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.