Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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
v3
Comments
Kschuler 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900