Maxime
Maxime

Reputation: 3165

Convert epochTime to NSDate

I need to convert an epoch time value to NSDate.. For exemple I have this epoch value (long) : 81915536 I'm interesting by the time value of the epoch value.

I have try that :

NSDate* date = [NSDate dateWithTimeIntervalSince1970:81915536];

but I got a 70's date....It's wrong.

But in a Java when I use this code, I obtain the right time value.

Date time = new Date(Long.valueOf(_epochTime));

    String minutes = time.getMinutes()+"";
    if(minutes.length()==1)
        minutes="0"+minutes;

    return time.getHours()+":"+minutes;

Someone can help me with this?

Upvotes: 0

Views: 750

Answers (1)

MByD
MByD

Reputation: 137322

The current UNIX time is 1310407007 the seconds you gave are actually in the seventies, see here: http://www.unixtimestamp.com/index.php.

Also, it doesn't seem that you check the year in your Java code, only the hours and minutes.

One more thing, if you want a constant to be treated as long and not as int, add a postfix of L: 81915536L

Upvotes: 2

Related Questions