Skip to content

Instantly share code, notes, and snippets.

@desaiashu
Created January 11, 2013 01:01
Show Gist options
  • Save desaiashu/4507119 to your computer and use it in GitHub Desktop.
Save desaiashu/4507119 to your computer and use it in GitHub Desktop.
Convert NSNumber representing epoch time to NSDate
// Epoch time (or unix time) is the number of seconds since Jan 1st 1970 00:00:00 UTC
// To convert an NSNumber representing epoch time to an NSDate object:
NSNumber *epochTimeOfSomeEvent = [NSNumber numberWithDouble:1357865700];
NSDate * dateOfThatSameEvent = [NSDate dateWithTimeIntervalSince1970:epochTimeOfSomeEvent];
// You can then compare this NSDate to the current date to get useful information from it
@dougfarre
Copy link

Passing a NSNumber to the dateWithTimeIntervalSince1970 is wrong.

@dougfarre
Copy link

Passing a NSNumber to the dateWithTimeIntervalSince1970 is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment