Date Formatter fun

  • Hey folks - i'm using a dateformatter to get a nice looking datetime:

    [today descriptionWithCalendarFormat:@"%a %I:%M %p"]

    however, I'm a little annoyed that the "hour" formatter (the %I) always
    gives the hour as a 2-digit - i.e. 9:45am will be formatted as 09:45am.

    This IS as written in the docs, however I was wondering it there was a
    simple way to get a single-digit hour when appropriate, whilst still
    being about to use the descriptionWithCalendarFormat method?

    My current method - to manually parse the date into day/hour/min/ampm
    vars - seems like such a lot of code for such a tiny issue...

    Anyone any ideas?

    Cheers.

    ---------------------------------------------------------------
    Duncan Campbell
    http://www.duncanandsarah.com/duncan
    ---------------------------------------------------------------
  • On 14 Feb 2005, at 2:39 am, Duncan Campbell wrote:

    > Hey folks - i'm using a dateformatter to get a nice looking datetime:
    >
    > [today descriptionWithCalendarFormat:@"%a %I:%M %p"]
    >
    > however, I'm a little annoyed that the "hour" formatter (the %I)
    > always gives the hour as a 2-digit - i.e. 9:45am will be formatted as
    > 09:45am.

    Use %1I for the hour to chop the leading zero.

    Regards,

    -Jeremy

    ===================================
    SkoobySoft, home of viJournal and Skooby Renamer
    email: <skoobysoft.info...> or visit:
    http://freespace.virgin.net/jeremy.dronfield/skoobysoft.html
    ===================================
previous month february 2005 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28            
Go to today