Urgent: Get Current Time

Discussion in 'iOS Programming' started by ilx.mac, Jul 23, 2009.

  1. ilx.mac macrumors member

    Joined:
    Mar 10, 2009
    #1
    Hi there,

    I need to get the current time in the format HH:MM:SS AM/PM. I have the date in textfield1.text. I tried using NDDate. But could not get the expected.
    Can some one help me ?


    Thanks in Advance!:)
     
  2. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #2
    Take a look at the NSDate method:
    Code:
    - (NSString *)descriptionWithCalendarFormat:(NSString *)[I]formatString[/I] timeZone:(NSTimeZone *)[I]aTimeZone[/I] locale:(id)[I]localeDictionary[/I]
    and read through Converting Dates to Strings
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    Unfortunately it appears that method isn't available on the iPhone (at least from a quick glance at the documentation).

    I think the recommended route is to use NSCalendar with NSDateComponents, or NSDateFormatter.
     
  4. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #4
    Oops, had the wrong documentation pulled up. Since that method isn't available, it looks like Kainjow's suggestion is the best way to go.
     

Share This Page