NSDate usage in iOS

Source: Internet
Author: User

The date method returns the current time (now) 02.  NSDate *date = [NSDate Date]; 03.//now:11:12:40 04.//date:11:12:50 05. Date = [NSDate datewithtimeintervalsincenow:10];//returns the current time 10 seconds after 06. Starting from 1970-1-1 00:00:00, 07. Date = [NSDate datewithtimeintervalsince1970:10];//returns 1970-1-1 00:00:00 time 10 seconds after 08. Randomly returns a relatively distant future time of 09.  Date = [NSDate distantfuture]; 10.//Randomly returns a relatively distant past time of 11.  Date = [NSDate distantpast]; 12.//returns the number of milliseconds that began to pass in 1970-1-1 13.  Nstimeinterval interval = [date timeIntervalSince1970]; 14.//Compare with other time 15.  NSDate *date2 = [NSDate Date]; 16.//Return to the earlier time 17.  [Date Earlierdate:date2]; 18.//Return to the time of the comparison later 19.  [Date Laterdate:date2];  20.21.  22.NSDate *date = [NSDate Date]; 23.//2013-04-07-11:14:45 24.  NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; //HH is 24 binary, HH is 12 binary 26.  Formatter.dateformat = @ "Yyyy-mm-dd HH:mm:ss";  //Formatter.locale = [[[Nslocale alloc] initwithlocaleidentifier:@ "ZH_CN"] autorelease]; NSString *string = [Formatter StringfromdatE:date];  NSLog (@ "%@", string); 30.//The time of the return of the green ruling is 31.   NSDate *date2 = [Formatter datefromstring:@ "2010-09-09 13:14:56"];

 

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.