1

I am parsing a JSON file which contains a timestamp. I want to convert this timestamp into an NSDate.

My code :

NSString *depart=[alternates valueForKey:@"startTime"];
NSTimeInterval intervaldep=[depart doubleValue];

NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:intervaldep];

But I am getting wrong date, e.g.: 44135-04-01 03:20:00 +0000 for time stamp 1330606668000. If any one has any idea please help. Thank you.

yuji
  • 16,695
  • 4
  • 63
  • 64
anjum
  • 556
  • 4
  • 22

2 Answers2

9

Your timestamp contains milliseconds, just divide your timestamp by 1000 (i.e. trim the last three zeros) and you should be fine.

tilo
  • 14,009
  • 6
  • 68
  • 85
2

Try to add the NSTimeZone to your NSDate, by default the dates are in GMT0

You can check the syntax here:

Convert UTC NSDate to local Timezone Objective-C

Community
  • 1
  • 1
Antonio MG
  • 20,382
  • 3
  • 43
  • 62