Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: iOS
Hi,
I am new to IOS development. I am using date in my application. When i tried to get the start date(i.e, 18-11-2012) of current week using NSCalendar, i am receiving a date which is one day previous than the actual date.i.e, 17-11-2012. But when convert the received date to string, it is displaying 18-11-2012. I dont know how to solve the issue. Please help me to solve the same ASAP.
 
Please find the code below:
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekComponents = [calendar components:NSWeekCalendarUnit | NSYearCalendarUnit fromDate:currentWeekStartDate];
[weekComponents setWeekday:1];
currentWeekStartDate = [calendar dateFromComponents:weekComponents];
NSLog(@"Current week start date is :%@", currentWeekStartDate);
 
Here, currentWeekStartDate variable holds the current date. And the output i received is,
 
Output:
Current week start date is :2012-11-17 18:30:00 +0000
 
I had posted the code and the output i got. Please find the same.
Posted 20-Nov-12 19:13pm
Edited 21-Nov-12 20:32pm
(no name)114K
v3
Comments
Kschuler at 21-Nov-12 11:52am
   
Can you post the actual code that you are using? Click the Improve question link and add it to your original question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,769
1 Sergey Alexandrovich Kryukov 6,338
2 DamithSL 5,408
3 Manas Bhardwaj 4,816
4 Maciej Los 4,195


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100