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?
- How do you tell what object is being touched in touchesBegan?
- Passing data between View Controllers in Swift (From TableView to DetailViewController)
- Updating new version to app store with different sqlite db structure
- My app crashes when running on my iPhone, but not in the simulator. What are some debugging techniques I can use to reso the issue?
- How to create ipa without Apple Developer Program in Xcode7
- Swift detect touch anywhere on the screen
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
- When to use global variables in Swift
- Creating a large GIF with CGImageDestinationFinalize – running out of memory
- Why is there an NSInteger?
- how to send push from iphone via urban airship?
- Using JSON in iOS
- How to tell ABPeoplePickerNavigationController to list only contacts that have an email address?
- how to draw a path one place to another place in google map sdk iOS?
- How to create selector with multiple argument in swift
- Can I change app icon programmatically
- Fix Core Data Fail
- XCode PhoneGap Localization
- Using sockets in Swift like in Java
- Android equivalent of NSUserDefaults in iOS
- Git and pbxproj
- iOS – How to refresh/update Core Data transient property?