Struggling with NSDateFormatter

May 21st, 2009

In PHP you have some great documentation on which format character to use in a string to get a certain output of a date. I thought this would be just as easy in xCode but I was wrong. The problem is, the official documentation of apple doesn’t tell you what specifiers are available to format your string. After searching endlessly on the internet I came across this site: Date Format Patterns. Which covers most of the format characters. For easy reference I decided to test all the date format patterns and create a table of my own in the style of the PHP documentation.

Format Character Description Example Return Values
Day
d Day of the month, 2 digits without leading zeros 1 through 31
dd Day of the month, 2 digits with leading zeros 01 through 31
D The day of the year 1 through 366
F The day of the week in a month 1 through 5 (eg. 2nd Wed in July)
g Julian day number (number of days since 4713 BC January 1) Example: 2451334
G Era designator abbreviated Example: AD
GGGG The full era designator name Example: Anno Domini
GGGGG A narrow textual representation of the era designator Example: A
Day of the Week
e
c
ISO-8601 numeric representation of the day of the week 1 (for Sunday) through 7 (for Saturday)
E
ccc
A textual representation of a day, three letters Mon through Sun
EEEE
cccc
A full textual representation of the day of the week Monday through Sunday
EEEEE
ccccc
A narrow textual representation of the day of the week Monday through Sunday
Week
w ISO-8601 week number of year 1 through 52
W ISO-8601 week number of month 1 through 4
Month
M
L
Numeric representation of a month, without leading zeros 1 through 12
MM
LL
Numeric representation of a month, with leading zeros 01 through 12
MMM
LLL
A short textual representation of a month, three letters Jan through Dec
MMMM
LLLL
A full textual representation of a month January through December
MMMMM
LLLLL
A narrow textual representation of a month Example: D
Year
y
yyyy
A full numeric representation of a year, 4 digits Example: 2009
yy A two digit representation of a year Example: 09
Y
YYYY
A full numeric representation of a ISO year, 4 digits Example: 2009
YY A two digit representation of a ISO year Example: 09
Time
a Lowercase Ante meridiem and Post meridiem AM or PM
h
K
12-hour format of an hour without leading zeros 1 through 12
hh
KK
12-hour format of an hour with leading zeros 01 through 12
H
k
24-hour format of an hour without leading zeros 0 through 23
HH
kk
24-hour format of an hour with leading zeros 00 through 23
m Minutes without leading zeros 0 through 59
mm Minutes with leading zeros 00 through 59
s Seconds without leading zeros 0 through 59
ss Seconds with leading zeros 00 to 59
A Milliseconds in day Example: 69540000
Timezone
zzzz A full textual representation of GMT timezone Example: Central European Time
Z Difference to Greenwich time (GMT) in hours in RFC 822 format Example: +0200
ZZZZ Difference to Greenwich time (GMT) in hours in GMT format Example: GMT+02:00

Example:

NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZZ"];

// will output something like: 2009-05-23 16:04:37 GMT+02:00
NSLog ([dateFormatter stringFromDate:today]);

My Very First iPhone Application Development

May 20th, 2009

I know I haven’t completed the website yet, but that’s because it has low priority at the moment. I need to finish my iPhone application first, when it has been sent to Apple I will continue to finish this website.

For a while now I have got this idea for an iPhone application in my head and to be able to make that idea into reality I had to start at the very beginning. Learning the iPhone SDK. It took me a couple of months to get familiar with the language, framework and the development environments but I think I understand it now.

Then I decided to come up with a working title for my project, which may very well be the title for the final product as well. After that I began to define the problem to which my application will have the solution for. In order to do this I had to define a target audience and talk to them about the problem. This really helped me see what I wasn’t seeying in the beginning, so I could recommend this to everyone.

The next step I took was the sketch phase. I made a very rough sketch of the concept to get a global idea of the solution. After this I immediatly went to the next phase, paper prototyping. This took me about a week, to completely sketch every screen you may come across when interacting with my application. This will let you think in depth about your applications structure. I was very pleased about the result and my genius solution I found for the problem.

I took these papers to my target audience only to find out that it was useless. They didn’t like my solution as it was to advanced, they wanted something more simple. I was so glad I didn’t program everything yet, because now I had to rethink everything. You can’t say this was a complete waste, because I got some very valuable information. I now know what they absolutly didn’t want and I got feedback on what they do want. So I had to get back to the drawing board.

Some days went by and I suddenly found the answer. I quickly drew my new screens and took them to the target audience once again. This time they were very enthusiastic, I hit the jackpot! Now I have the whole application on paper. Next step, building!

I just entered this new exciting phase and decided to start with some basics. The application title, icon and default (splash) screen. Now I don’t have any design skills, part from some experimental design like the theme for this website, so I need to yet again learn.

For creating a good iPhone application icon you do not only need to have a good idea or a sophisticated design, but you also need to follow the rules.I was told that a good starting point would be to read the Apple Human Interface Guidelines just to get a basic knowledge about the philosophy of Mac OSX User Interface Design. The next step will be to consider what I want to create.

To be continued …

Hello visitor!

May 19th, 2009

Since yesterday I am rebuilding my website because of some ultra spam on my previous site. I am now running the latest version of WordPress and it works surprisingly well. The theme is not yet complete, it still needs some work and also the content needs to be replaced. The iPhone Duck Hunt tutorial will be back, together with the Multi-Touch applications and the MSN tutorial. Stay tuned.