How can I add a zero to the left of a 1 digit integer ? Is there any objective C function to perform this? I am needing this开发者_StackOverflow社区 so I can have only one NSDateFormat @"ddMMyyyy" thanks
I want to add a zero to the left of an integer which is less than 10, I don't want to use an if statement. Is there any function or way to achieve this?
Use the string format specifier %02d
and any single digit integer will be padded with a zero in a string.
You can use string formatters to add padding to your integer value as shown here: Help in padding numerical strings
精彩评论