iOS code implementation time settings NSDate

Source: Internet
Author: User

This article reprinted to http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_ Gtg3lkrntv5h87x0aykchvwyjbz2hdcb2jvptymrhl6hno2fx_u3tedgzq//1), creates an object that is assigned the NSDate object created by the current date, and is always given a time of 0 time zone, chin A is East eight, it takes 8 hours.
NSDate *date = [NSDate Date];
Nstimezone *zone = [Nstimezone systemtimezone];//Modify Time zone
Nsinteger interval1 = [Zone secondsfromgmtfordate:date];//modify Time zone
NSDate *localdate1 = [date datebyaddingtimeinterval:interval1];//modify time zone
NSLog (@ "Today%@", localDate1);

2), create a date for tomorrow at this time (the interval is in seconds) Datewithtimeintervalsincenow:
NSDate *tomorrow = [nsdate datewithtimeintervalsincenow:24 * 60 * 60];
Nsinteger interval2 = [zone Secondsfromgmtfordate:tomorrow];
NSDate *localdate2 = [Tomorrow Datebyaddingtimeinterval:interval2];
NSLog (@ "Tomorrow%@", localDate2);

3), create a date at this time yesterday
NSDate *yesterday = [nsdate datewithtimeintervalsincenow:-24 * 60 * 60];
Nsinteger interval3 = [zone secondsfromgmtfordate:yesterday];
NSDate *localdate3 = [Yesterday Datebyaddingtimeinterval:interval3];
NSLog (@ "Yesterday%@", localDate3);

iOS code implementation time settings 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.