depicus

  just another nerd on the interweb…



  • home
  • gallery
  • play page
  • support
  • videos
  • what is depicus

iDev – Getting a good looking date with prefix

Author: The Man



Not sure it should take this much code but….

View Code OBJC
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
29
30
31
32
33
34
35
36
37
38
39
40
41
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MMMM yyyy"];
 
    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm"];
 
    NSDateFormatter *dayFormat = [[NSDateFormatter alloc] init];
    [dayFormat setDateFormat:@"d"];
 
    NSDate *now = [[NSDate alloc] init];
 
    NSString *theDate = [dateFormat stringFromDate:now];
    NSString *theTime = [timeFormat stringFromDate:now];
    NSString *theDay = [dayFormat stringFromDate:now];
 
    NSString *dayWithPrefix;
 
    if ((theDay == @"1") || (theDay == @"21") || (theDay == @"31"))
    {
        dayWithPrefix = [NSString stringWithFormat:@"%@st", theDay];
    }
    else if ((theDay == @"2") || (theDay == @"22"))
    {
        dayWithPrefix = [NSString stringWithFormat:@"%@nd", theDay];
    }
    else if ((theDay == @"3") || (theDay == @"23"))
    {
        dayWithPrefix = [NSString stringWithFormat:@"%@rd", theDay];
    }
    else
    {
        dayWithPrefix = [NSString stringWithFormat:@"%@th", theDay];
    }
 
 
    [lblDateTime setText:[NSString stringWithFormat:@"Date: %@ %@ Time: %@", dayWithPrefix, theDate, theTime]];
 
    [dateFormat release];
    [timeFormat release];
    [theDay release];
    [now release];
Tweet

Tags: Apple, Code, iPad, iPhone, iPod Touch, XCode

This entry was posted on Thursday, August 5th, 2010 at 9:30 pm and is filed under Software Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “iDev – Getting a good looking date with prefix”

February 1st, 2012 at 11:23 am

murray king says:

Thanks for the post.
Quick note
-must be a typo for
[theDay release]; should be [dayFormat release] instead. theDay is just autoreleased.

February 1st, 2012 at 11:35 am

The Man says:

Yes left it in there to see if anybody noticed…. or I am just not that a good programmer :)

Thanks.

Leave a Reply

  • how i pay the bills

  • google rank getter

    Android Apache Aperture Apple App Store bbPress Bike Bug Canon 7D Code Dell DotNet Dropbox Fail Firefox forum Frustration Golf iPad iPhone iPod Touch Java Kenya Linksys Macbook Pro Netgear Objective C Open Source OSX PHP Rejected Safari Server Skype Support Ubuntu Update WakeOnLan Wake On Lan Wifi Windows Windows 7 Phone Wireshark Wordpress XCode
  • depicus in africa

    depicus in africa
  • friends

    • Agency Manager
    • AllClear Travel
    • Climbing Tikes
    • Globe Bloggers
    • Marchday
    • The Travel Toad
  • gallery

    Bisley Developments Ltd IMG_2303 Bisley Developments Ltd IMG_3072
  • videos

    Vimeo

    YouTube
  • twitter

    • Holy geekness batman we have an Arduino doing Wake on Lan forwarding programmed in less than 4 hours… amazing - #iamanubergeektoday view
    • Arduino WoLF app coming along nicely view
    • RT @pasm69: On the one hand we are in a #drought says #thameswater, on the other £4.1B to throw rainwater down the #supersewer #itisjust ... view
  • recent comments

    • Sef: Yo, thats 720p @ 60fps. Huge Difference… in file size, processing, everything. DSLRs aren’t there...
    • Finson: Worked..!! Replaced all the InstallOnLHS and InstallOnWinXP with value 0 and the installation completed...
    • Geux: Terminal command didn’t work, but editing the plist manually did the trick. Thanks !!!
    • Nebras Alattar: Hi The code that you posted is very useful, but i faced a problem when i run the app i got the...
    • leon: how can I get the ImageIO.framework ? I’ve read that it doesn’t exist for iphone!!!! Can anyone...
  • archives

    • May 2012 (2)
    • April 2012 (4)
    • February 2012 (8)
    • January 2012 (6)
    • December 2011 (7)
    • November 2011 (1)
    • October 2011 (2)
    • September 2011 (2)
    • August 2011 (4)
    • July 2011 (6)
    • June 2011 (9)
    • May 2011 (8)
    • April 2011 (2)
    • February 2011 (6)
    • January 2011 (14)
    • December 2010 (9)
    • November 2010 (8)
    • October 2010 (14)
    • September 2010 (6)
    • August 2010 (9)
    • July 2010 (1)
    • June 2010 (2)
    • May 2010 (2)
    • April 2010 (2)
    • March 2010 (11)
    • February 2010 (3)

Copyright © - depicus | Entries (RSS) | Comments (RSS)

WordPress theme butchered and amended by me.