Click here to Skip to main content
11,576,692 members (61,275 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: iOS
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,

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 18:13pm
Edited 21-Nov-12 19:32pm
(no name)136.8K
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 Sergey Alexandrovich Kryukov 251
1 Abhinav S 170
2 Lucifier Rocks 105
3 DamithSL 95
4 Dave Kreskowiak 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 626
2 Abhinav S 483
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2015
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