1

hi every one I'm using this code, through this I'm getting wrong time,i need time with GMT format but it showing without GMT, that is by using this I'm getting time 2011-11-01 07:30:11 +0000 while the current time here right now is 12:30 pm. please help me in getting Current date and time in GMT format. thanks.

NSDate *today = [NSDate date];
NSString *str= [NSString stringWithFormat:@"todaysss daterrrr----%@",today];
NSLog(@"todayssss date time-------- %@",str);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter release];
Alan Bond
  • 37
  • 5
  • http://stackoverflow.com/questions/838893/my-nsdateformatter-works-only-in-the-iphone-simulator i hope this will be more helpfull for you http://cocoawithlove.com/2009/05/simple-methods-for-date-formatting-and.html – Marios Nov 01 '11 at 07:47

1 Answers1

2

I think this may help you.

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
NSString* dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"Date/Time is %@", dateString);