NSDateFormatter format strings

Guides By 5 years ago

Every time I bookmark one of these lists it seems to disappear soon after, so it’s time to make my own (laid out to my liking):

Format Description Allows 0 padding Example
a Period X AM/PM
A Millisecond of Day 0-86399999
s Second 0-59
m Minute 0-59
h Hour (12hr) 1-12
H Hour (24hr) 0-24
d Day of Month 1-31
D Day of Year 1-366
c Day of Week X 1-7
ccc Day of Week (Abbreviated) X Sun/Mon/Tue…
cccc Day of Week X Sunday/Monday/…
W Week of Month 1-5
w Week of Year 1-53
M Month 1-12
MMM Month (Abbreviated) X Jan/Feb/Mar…
MMMM Month X January/February/…
y/yyyy Year 2012/2013/…
yy Year (2 digits) X 12/13/…
q Quarter 1-4
qqq Quarter (short) X Q1/Q2/Q3/Q4
qqqq Quarter (long) 1st quarter/2nd…
g Julian Day (days since 4713 BC) 2456200
G Era (Abbreviated) X BC/AD
GGGG Era X Before Christ/
Anno Domini
v General Timezone (Abbreviated) X AET
vvvv General Timezone X Eastern Australia Time
z Timezone (Abbreviated) X AEDT
zzzz Timezone X Australian Eastern Daylight Time
Z GMT Offset X +1100
  • cwagdev

    Thank you! I have the same experience.

  • Yea, same here. Thanks for doing this. I’ve bookmarked it now, hopefully this won’t disappear aswell…

  • Rainier Wolfcastle

    Why on earth have Apple NOT added this to the documentation? And if it’s there, why in God’s name can’t I find it? Apple’s docs are horrible!