h1

DateFormatter

augusti 24, 2010

DateFormatter can be hell. However….

Character Matches/Outputs Multiples
y Year 1, 2 or 4 ‘y’s will show the value, 2 digit zero-padded value or 4 digit zero-padded value respectively
M Month 1, 2, 3, 4 or 5 ‘M’s will show the value, 2 digit zero-padded value, short name, long name or initial letter months
d Day of Month 1 or 2 ‘d’s will show the value or 2 digit zero-padded value representation respectively.
E Weekday 1, 2, 3, 4 or 5 ‘e’s will show the value weekday number, 2 digit zero-padded value weekday number, short name, long name or initial letter respectively. Weekday numbers starts on Sunday. Use lowercase ‘e’ for weekday numbers starting on Monday.
a AM or PM No repeat supported
h Hour 1 or 2 ‘h’s will show the value or 2 digit zero-padded value representation respectively. Use uppercase for 24 hour time.
m Minute 1 or 2 ‘m’s will show the value or 2 digit zero-padded value representation respectively.
s Second 1 or 2 ‘s’s will show the value or 2 digit zero-padded value representation respectively.
z Timezone 1, 2, 3 or 4 ‘z’s will show short acronym, short name, long acronym, long name respectively. Use uppercase to show GMT offset instead of name — 1 or 2 digit zero-padded values shows GMT or RFC 822 respectively.

Ex.

[inputFormatter setDateFormat:@"MM/DD/YYYY h:m:s a"]; // 8/24/2010 8:00:00 AM

Then remember to do the outputformatter in the format you want.

//JFR

Lämna en kommentar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logga ut / Ändra )

Twitter-bild

You are commenting using your Twitter account. Logga ut / Ändra )

Facebook-foto

You are commenting using your Facebook account. Logga ut / Ändra )

Ansluter till %s

Follow

Get every new post delivered to your Inbox.