Click here to Skip to main content
12,623,776 members (28,692 online)
Rate this:
 
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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2016
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