How can I get the day_of_month, month and the year into parameters as integers?
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar start_date = Calendar.getInstance();
System.out.println(dateFormat.format(start_date.getTime()));
int day = start_date.get(Calendar.DAY_OF_MONTH);
int month = start_date.get(Calendar.MONTH);
int year = start_date.get(Calendar.YEAR);
String result = day + "/" + month + "/" + year;
but, the date today is: 01/12/12, while the result is: 01/11/12.
This is expected behaviour. Month goes from 0 to 11. You can check this by issuing:
By the way, to convert dates to Strings, you should really use SimpleDateFormat
(sidenote, but important: SimpleDateFormat is not thread safe very much not thread safe, so don’t try to optimize by using them as static instances in a multithreaded environment! This is also stated in the API doc:
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.)