-1

I have been trying this since long back, I need current UTC of current data time is it possible, If possible how can I achieve this.

what I have tried till

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"ddMMyyyy HH:mm"];

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[formatter setTimeZone:timeZone];

NSDate *now = [NSDate date];
NSString *dateAsString = [formatter stringFromDate:now];

Thanks, Nikhil.Ch

Larme
  • 24,190
  • 6
  • 51
  • 81

1 Answers1

1

The NSDate object is already in UTC format when you perform initialization. Now the string representation of the UTC format might not be what you want so you can change the format to the following (or something similar):

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSString *localDateString = [dateFormatter stringFromDate:currentDate];
SierraMike
  • 1,539
  • 1
  • 11
  • 18
  • Hi Sean, I have tried this code but when i checked in google , The UTC time it shows now is 2:00 pm , when i execute the above code for only time it shows "20:30.572z". Where i"m going wrong please help – nikhil challagulla Feb 19 '15 at 15:02