Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNumber timestamp in milliseconds to NSDate [duplicate]

Tags:

objective-c

I have an NSNumber with a value of 1369605600000.

The value is a timestamp in milliseconds that I want to convert into an NSDate. I tried converting it with dateWithTimeIntervalSince1970 but i dont know how to divide the NSNumber by 1000 to convert it to seconds first.

like image 246
user35938 Avatar asked Dec 15 '22 04:12

user35938


1 Answers

Try this:

NSTimeInterval seconds = [aNumber doubleValue] / 1000;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:seconds];
like image 188
John Cromartie Avatar answered Jan 18 '23 22:01

John Cromartie