Format string for NSDateFormatter to produce milliseconds

h4wkeye picture h4wkeye · Apr 15, 2011 · Viewed 8.2k times · Source

Since my date is well formatted now all there is left for me to do is to print milliseconds too.

I already tried setDateFormat yyyy/mm/dd hh:mm:ss:ms

That didn't work. Any advice?

Answer

Vladimir picture Vladimir · Apr 15, 2011

Try to use 'SS' specifier (with number of S's equal to number of digits you want to get - 3 in your case), e.g.

[formatter setDateFormat:@"yyyy/MM/dd hh:mm:ss:SSS"];