Related Operations for Iosnsdate

Source: Internet
Author: User

Gets the current time based on Greenwich Mean time display

Time 8 hours UK Greenwich 7 HOURS

NSDate *date = [NSDate Date];

NSLog (@ "%@", date);

Nszone Calculating time zones

Get a time parameter based on the current time is seconds

NSDate *somedate = [NSDate datewithtimeintervalsincenow:3600];

NSLog (@ "%@", somedate);

Get a long time

NSDate *futuredate = [NSDate distantfuture];

NSLog (@ "%@", futuredate);

For a long time in the past

NSDate *pastdate= [NSDate distantpast];

NSLog (@ "%@", pastdate);

The future of 200s

NSDate *date1 = [NSDate datewithtimeintervalsincenow:200];

Compare date and Date1

Return to an earlier time

NSDate *dateearly =[date earlierdate:date1];

NSLog (@ "date early%@", dateearly);

Return to a later time

NSDate *datelater = [date laterdate:date1];

Time format Conversion Class NSDateFormatter

Create a time conversion object

NSDateFormatter * Dateformatter = [[NSDateFormatter alloc]init];

Format the time of the conversion

Use the time conversion format provided to us by the system

Dateformatter.datestyle =kcfdateformatterfullstyle;

Returns the time corresponding string based on the provided time

NSString *string = [Dateformatter stringfromdate:date];

NSLog (@ "... %@ ", string);

Self-customizing formats

Year Month day hour minute second

Dateformatter.dateformat = @ "Yyyy:MM:dd HH:mm:ss";

NSString *STRINGN = [Dateformatter stringfromdate:date];

NSLog (@ "%@", STRINGN);

Returns the time based on the input string

NSString *str = @ "2014-05-12 12:30:00";

Custom format conversion format based on input time format

NSDateFormatter *format = [[NSDateFormatter alloc]init];

Format.dateformat = @ "Yyyy-mm-dd HH:mm:ss";

Output time based on string nsdate

NSDate *somed = [format datefromstring:str];

NSLog (@ "%@", somed);

Nszone nscalendarcomponent

Nsvalue encapsulated struct C language array

int a[4] ={1,2,3,4};

Create a Nsvalue

Nsvalue *value = [[Nsvalue alloc]initwithbytes:a Objctype: @encode (Int[4])];

int b[10];

Take it out.

[Value getvalue:b];

NSLog (@ "%d", b[2]);

Structural body

struct student{

int age;

};

Variable C age 10

struct student C;

c.age=10;

Encapsulating the structure to the Nsvalue

Nsvalue *value1 = [Nsvalue value:&c withobjctype: @encode (struct student)];

Take the students out

struct student D;

[Value1 getvalue:&d];

NSLog (@ "%d", d.age);

Related Operations for Iosnsdate

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.