iphone - Get current date string for special format -


i writing iphone app now. want current date , time following format.

thu, 18 apr 2013 01:41:13  

how can achieve this?

the documentation setdateformat: in nsdateformatter class reference links data formatting guide.

in data formatting guide, date formatters > use format strings specify custom formats > fixed formats section links appendix f of *unicode technical standard #35.

appendix f, while obtuse, tells everything:

  • use e short week day name.
  • use d day of month.
  • use mmm short month name.
  • use y year.
  • use hh hour.
  • use mm minute.
  • use ss second.

we can test without writing whole objective-c program using python's cocoa bindings:

:; python python 2.7.2 (default, oct 11 2012, 20:14:37)  [gcc 4.2.1 compatible apple clang 4.0 (tags/apple/clang-418.0.60)] on darwin type "help", "copyright", "credits" or "license" more information. >>> cocoa import * >>> f = nsdateformatter.new()          >>> f.setdateformat_('e, d mmm y hh:mm:ss') >>> f.stringfromdate_(nsdate.new()) u'wed, 17 apr 2013 10:40:25' 

in objective-c, looks this:

nsdateformatter *f = [nsdateformatter new]; f.dateformat = @"e, d mmm y hh:mm:ss"; nslog(@"%@", [f stringfromdate:[nsdate new]]); 

note expensive create nsdateformatter. should create once , keep around if formatting many dates.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -