Object-c NSDate

Source: Internet
Author: User

  

NSDate Common methods

NSDate *date=[nsdate Date];//gets the current timeNSLog (@"%@", date);
NSDate*date1=[nsdate datewithtimeintervalsincenow:- -];//returns the current time as a benchmark, and then takes 60 seconds toNSLog (@"----%@", date1);
NSDate*date2=[nsdate dateWithTimeIntervalSince1970: +];//from 1970 onwards, after a number of secondsNSLog (@"%@", Date2);
NSDate*date3=[date2 Datebyaddingtimeinterval: -];//time is the standard plus a few secondsNSLog (@"%@", Date3);
Nstimeinterval Intervel=[date timeIntervalSince1970];//The number of seconds from 1970 to a certain time
NSLog (@ "%lf", intervel);
Nstimeinterval Intervel1=[date Timeintervalsincedate:date];//Count two time intervals (in seconds)
NSLog (@ "%lf", Intervel1);
Nstimeinterval intervel2=[Date1 Timeintervalsincenow]; NSLog (@"%LF", Intervel2);
NSDate*date4=[date Laterdate:date2];//get two more late (longer than 1970 months)NSLog (@"%@", date4);
NSDate *date=[NSDate Date];
//DateTime Formatted ObjectNSDateFormatter *formater=[[NSDateFormatter alloc]init];
//Set Date display format[Formater Setdateformat:@"YYYY--MM--DD HH:mm:ss"];//after formatting, the error does not exist. //Lowercase is a 12-hour, capital 24-hour system
//formatting datetime objects (converting date objects to strings)NSString *str=[formater Stringfromdate:date];//Replace a date with a string
NSLog (@"%@", str);

        //Resolve Time DifferenceNSString *str=@"2015-11-3 10:20:00"; NSDateFormatter*foma=[[NSDateFormatter alloc]init]; [Foma Setdateformat:@"YYYY-MM-DD Hh:mm:ss"]; NSDate*date=[Foma Datefromstring:str]; //First Kind//and Greenwich, the differenceNsinteger timeoff=[[Nstimezone SYSTEMTIMEZONE]SECONDSFROMGMT]; //jet lag ConversionDate=[Date Datebyaddingtimeinterval:timeoff]; NSLog (@"%@", date);//The second Kind//set the time zone to UTC International calibration Time[Foma Settimezone:[nstimezone Timezonewithname:@"UTC"]]; NSDate*date1=[Foma Datefromstring:str]; NSLog (@"%@", date1); //Third Kind[Foma Settimezone:[nstimezone TIMEZONEFORSECONDSFROMGMT:0]]; NSDate*date1=[Foma Datefromstring:str]; NSLog (@"%@", date1);

Object-c NSDate

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.