In my app, want to get the day (i.e. Sunday
, Monday
,etc.) from the date.
My code is as follow:
NSDate *currentDate = [NSDat
Try this :
NSCalendar* calender = [NSCalendar currentCalendar];
NSDateComponents* component = [calender components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
return [component weekday]; // 1 for Sunday, 2 for Monday, and so on...
and see also this Day Name From NSDate? and this https://discussions.apple.com/thread/1700102?start=0&tstart=0
Edit
try this
NSString * time = @"2013-06-30T11:00:26+0100";
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date1 = [df dateFromString:time];
long lgTime = (long)[date1 timeIntervalSince1970];
NSLog(@"%ld", lgTime);
NSCalendar* calender = [NSCalendar currentCalendar];
NSDateComponents* component = [calender components:NSWeekdayCalendarUnit fromDate:date1];
NSLog(@"date=%@ === %@",[NSDate date],date1);
NSLog(@"day= %d",[component weekday]); ///it return 1