I need that the returned date string would have the format:
"DD/MM/YYYY"
i.e. 2 digits for day and month and 4 digits for year.
Example:
int day = 11;
int month = 2;
int year = 1997;
be returned as
"11/02/1997"
Any suggestions?
I need that the returned date string would have the format:
"DD/MM/YYYY"
i.e. 2 digits for day and month and 4 digits for year.
Example:
int day = 11;
int month = 2;
int year = 1997;
be returned as
"11/02/1997"
Any suggestions?
First of all your date format is wrong.change
"DD/MM/YYYY"
to
"dd/MM/yyyy"
Meaning of d
and D
is differ same as y
and Y
Read about that.
Answer to the next part.
You can use Calender for this
int day = 11;
int month = 2; // 0th January. 1st February... so on
int year = 1997;
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month-1);
calendar.set(Calendar.DATE,day);
DateFormat df=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(df.format(calendar.getTime()));
Out put:
11/02/1997
You may need to read about Calender too.
Calendar calendar = Calendar.getInstance();
calendar.set(1997, 11, 2);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.format(calendar.getTime()));