Get time and formatting--today, yesterday and tomorrow

Source: Internet
Author: User

1. Get today

/*!     *  @brief Get today     *   //1. Get accurate events for the current system (+ 8 hours)        nsdate *date = [NSDate date];//Get Time object        nstimezone *zone = [N Stimezone Systemtimezone]; Get the time zone of the system        nstimeinterval time = [Zone secondsfromgmtfordate:date];//returns the difference between the current and system GMT in seconds        nsdate *datenow = [Date datebyaddingtimeinterval:time];//and then add the bad time, is the current system accurate time

2. Get Yesterday and tomorrow

/*!     *  @brief get yesterday and tomorrow * *    nstimeinterval secondsperday = *        NSDate *date = [[NSDate alloc] initwithtimeintervalsincenow:-secondsperday];    Nstimezone *zone = [Nstimezone systemtimezone]; Get the time zone of the system        nstimeinterval time = [Zone secondsfromgmtfordate:date];//returns the difference between the current and system GMT in seconds        //Yesterday    NSDate *yesterday = [date datebyaddingtimeinterval:time];    Tomorrow    nsdate *tomorrow = [[NSDate alloc] initwithtimeintervalsincenow:secondsperday];

3. Time Format

/*!     *  @brief Time format *     /        nsdate *date = [NSDate date];//Get Time object        nsdateformatter *formatter = [[ NSDateFormatter alloc] init];        [ForMatter setdateformat:@ "Hh-mm-ss yyyy-mm-dd"];        NSString *datestr = [ForMatter stringfromdate:date];   

Acquisition time can also be nscalendar with the system.

Get time and formatting--today, yesterday and tomorrow

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.