iPhone SDK, how to get NSDate object of coming friday's 20:00?
Does anyone know how to get the NSDate of the coming friday’s 20:00 ?
- How to kill a Thread with Objective C?
- 'Communications error: <OS_xpc_error:' while recording video
- How to use NSCoder
- What's the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?
- Getting date from off by a few hours
- Using - observeValueForKeyPath:ofObject:change:context: in Swift 3
Solutions Collect From Internet About “iPhone SDK, how to get NSDate object of coming friday's 20:00?”
Yes, this article teaches you how to get the current week’s Sunday.
I quickly adapted it to get friday at 20:00 (Assuming a Gregorian calendar)
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];
- What's the best way to call an IBAction from with-in the code?
- How to split a string by new lines in Swift
- EaseOut action with custom SKAction
- Cannot find Xcode 4 new project template for navigation controller based app. Any alternative?
- Core Data file's Location iOS 10
- Crash when process pixel after crop an image
- How to Programmatically check and open an existing app in iOS 8?
- How to add properties to NSMutableArray via category extension?
- Apple Push Notification Authentication Key (Sandbox & Production)
- Calculating delta in SpriteKit using Swift
- iOS – Split View Controller – How do I get a pointer (reference) to the Detail View Controller from inside the Master View Controller?
- how to init a UIButton subclass?
- NSData to NSString with JSON response
- Drag the canvas in interface builder
- Why does test iAd for barebones project not display?