java - Getting months as 01,02 instead of 1,2 -


i working calender class , more need 12 months 2 numbers.

if use following code:

 int month = (mycalendar.get(calendar.month)) +1; 

this different months: 1,2,3,4,5,6,7,8,9,10,11,12

but need is: 01,02,03,04,05,06,07,08,09,10,11,12

this beacuse need make substrings , go wrong if number of ints get. there easy way fix this?

i use if statement , check if whole date 5 numbers, add 0 , 3 position, feels cumberstone.

the reason loading "1" instead of "01" because stored in int, following if statement:

string smonth = ""; if (month < 10) {     smonth = "0"+string.valueof(month); } else {     smonth = string.valueof(month); } 

then use smonth instead of month.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -