Getting The Unix Time

Discussion in 'iOS Programming' started by macprogrammer80, Jun 27, 2009.

  1. macprogrammer80 macrumors newbie

    Joined:
    Apr 22, 2009
    #1
    What is the quickest way of getting the Unix time with the iPhone?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #3
    If you want to use Cocoa you can call
    Code:
    [[NSDate date] timeSince1970]
    for the Unix epoch (00:00:00 GMT, 01/01/1970) or
    Code:
    [[NSDate date] timeSinceReferenceDate]
    for the Mac OS X epoch (00:00:00 GMT, 01/01/2001). Both of these return an NSTimeInterval type (which is really just a typedef'd double and measured in seconds).
     
  4. CaptSaltyJack macrumors 6502

    Joined:
    Jun 28, 2007
    #4
    Do not use epoch time. It will be completely broken in 2038.

    I'm kidding. :) I mean, it WILL be broken in 2038, but obviously that's 29 years from now.
     
  5. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #5
    Not really. Most operating systems that use epoch time are moving to a 64-bit wide time_t instead of a 32-bit one so it's really a non-issue. You may want to then want to worry about the 64 bit value overflowing but I'm relatively sure you should be more concerned with the sun burning out. This is a non-issue when using the Cocoa API as it uses a double to represent the time.
     

Share This Page