Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, <a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/DatesAndTimes/Articles/dtCalendricalCalculations.html" rel="noreferrer">this article</a> teaches you how to get the current week's Sunday.</p> <p>I quickly adapted it to get friday at 20:00 (Assuming a Gregorian calendar)</p> <pre><code>NSDate *today = [[NSDate alloc] init]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; // Get the weekday component of the current date NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:today]; /* Create a date components to represent the number of days to add to the current date. The weekday value for Friday in the Gregorian calendar is 6, so add the difference between 6 and today to get the number of days to add. Actually, on Saturday that will give you -1, so you want to subtract from 13 then take modulo 7 */ NSDateComponents *componentsToAdd = [[NSDateComponents alloc] init]; [componentsToAdd setDay: (13 - [weekdayComponents weekday]) % 7]; NSDate *friday = [gregorian dateByAddingComponents:componentsToAdd toDate:today options:0]; /* friday now has the same hour, minute, and second as the original date (today). To normalize to midnight, extract the year, month, and day components and create a new date from those components. */ NSDateComponents *components = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate: friday]; // And to set the time to 20:00 [components setHour:22]; friday = [gregorian dateFromComponents:components]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload