I had some issue with date: I get the current date (2010-10-27) in NSDate,converting it to NSString ...it's k But again when I try to get the date from String i.e NSDate , I am always getting the day before date . i.e (2010-10-26) instead of getting (2010-10-27).
Plz help me.....I tried alot for the same..with every possibilty
Here is my Code:
NSDate *now = [NSDate date];
NSString *date=[NSString stringWithFormat:@"%@",now];
NSArray *temp=[date componentsSeparatedByString:@" "];
NSString *currdate=[temp objectAtIndex:0];
NSDateFormatter *df1 = [[NSDateFormatter alloc] init];
[df1 setDateFormat:@"yyyy-MM-dd"];
NSDate *curdate = [df1 dateFromString: currdate];
[df1 release];
NSDateFormatter *df=[[NSDateFormatter alloc]init];
[df setDateFormat:@"yyyy-MM-dd"];
[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; //Tried to set the Time Zone also
//[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_EN"] autorelease]];
if([appDelegate.calGlobalDate isEqualToString:@""]) //My condition
{appDelegate.calGlobalDate=currdate;}
NSLog(@"%@",appDelegate.calGlobalDate); //I am getting right date over here
NSDate *ldate=[df dateFromString:appDelegate.calGlobalDate];
NSLog(@"%@",[NSString stringWithFormat:@"%@",ldate]); // But for here it always shows me yesterday's date. Here comes the problem
[df release];
Thanks in advance !!!