Get the date of sunday of the current week in IOs
I have searched for the solution to find the date of the sunday of the particular week.I have found questions that have been answered but it doesnt show the correct date of sunday.
NSCalendar *calendar = [NSCalendar currentCalendar]; unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday | NSCalendarUnitWeekOfYear; NSDateComponents *comps = [calendar components:unitFlags fromDate:[NSDate date]]; comps.weekday = 1; //Sunday comps.weekOfMonth = 1; NSDate *sundayDate = [calendar dateFromComponents:comps];
When i print out the date it gives this.
2015-07-08 10:14:00 +0000
Its the current date.What am i doing wrong?
Solutions Collect From Internet About “Get the date of sunday of the current week in IOs”
hope this helps you :
NSDate *today = [NSDate date]; NSCalendar *calenderObj = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; calenderObj.firstWeekday = 1; // Sunday = 1, // NSDateComponents *components = [calenderObj components:NSWeekOfYearCalendarUnit fromDate:today]; NSDate *objDate = nil; [calenderObj rangeOfUnit:NSWeekCalendarUnit startDate:&objDate interval:NULL forDate:today]; NSLog(@" === %@", objDate);
=== 2015-07-15 10:26:00 +0000
- How do I reference a dependent project built with a different configuration in Xcode?
- How to present an AlertView from a UICollectionViewCell
- convert UIImage to NSData
- shouldAutoRotate Method Not Called in iOS6
- How to extend keyboard gradient on iPhone?
- _GSRegisterPurpleNamedPortInPrivateNamespace – App Store Crash (code attached)
- Xcode 9.2 Upload to App Store fails with description length and invalid toolchain errors
- Is there a function that checks if a character in a string is a letter in the alphabet? (Swift)
- Mapping iOS 7 constants to 2G, 3G, 4G, LTE etc
- In app purchases restore Button
- Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping – no restart will be attempted
- Display Separator only for the Available CellForRow in UITableView
- Would like to learn how to use OpenGL within Objective-C, but have no idea where to start. Help?
- PNG/JPEG representation from CIImage always returns nil
- How to get Beats per minutes of a song in objective-c