-2

simple one that is bugging me and can't work it out. I am wishing to convert the current UTC to a string of number but the hour is wrong? when its 00 hour it is displaying as 10.. space is there just to make it easier to read at moment.

Log:

2014-09-01 10:24:16.337 MyApp[44834:60b] 2014-09-01 00:24:16 +0000
2014-09-01 10:24:16.339 MyApp[44834:60b] 20140901 102416

Code:

NSDate *currentDate = [[NSDate alloc] init];
NSLog(@"%@", currentDate);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd HHmmss"];
NSString *currentDateString = [dateFormatter stringFromDate:currentDate];
NSLog(@"%@", currentDateString);
veggyaurus
  • 241
  • 1
  • 2
  • 11
  • No, it's not error 2014-09-01 00:24:16 +0000 is current time with GMT+0 is your current timezone +10 ? http://stackoverflow.com/questions/6229024/nsdate-format-outputting-wrong-date – Huy Nghia Sep 01 '14 at 00:36

1 Answers1

1

The NSDate object you're creating is UTC, but the date formatter you create is using the system/local timezone, hence the time difference.

Mike
  • 9,765
  • 5
  • 34
  • 59