-1

I have a timestamp measured in milliseconds since January 1, 1970, 00:00:00 UTC.

eg. input "takeoffTime": "1396614600000" output in date format

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Pankaj Bhardwaj
  • 2,081
  • 1
  • 17
  • 37
  • possible duplicate of [Convert milliseconds to NSDate](http://stackoverflow.com/questions/2741199/convert-milliseconds-to-nsdate) – Jacob Zwiers Jul 13 '15 at 16:30

3 Answers3

3

You can do this by doing the following:

[NSDate dateWithTimeIntervalSince1970:1396614600000/1000];

This will give you 2014-04-04 12:30:00 +0000. You should read up on how to pass messages (call methods) here: How can I call a method in Objective-C?

Community
  • 1
  • 1
Chee-Yi
  • 880
  • 10
  • 17
1

The NSDate class gives you this method + (instancetype)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds.

Look here: Apple docs

Philip
  • 2,287
  • 1
  • 22
  • 37
  • judging from the fact that he has no decimal point and has an actual amount of millisecond he additionally needs to divide by `1000.0` because `NSTimeInterval` denotes `seconds`. – luk2302 Jul 13 '15 at 16:20
  • @PankajBhardwaj then read some tutorial please. It has been asked and answered and written out more than a million times how to convert a string to a `int` or `long`. Take a look at the documentation and read about it. – luk2302 Jul 13 '15 at 16:25
1
NSString* takeOffTime = @"1396614600000";
double miliSec = takeOffTime.doubleValue;
NSDate* takeOffDate = [NSDate dateWithTimeIntervalSince1970:miliSec/1000];
Yedidya Reiss
  • 5,316
  • 2
  • 17
  • 19