I am trying to format a date as part of a string field, I am sure that I am doing this the wrong way and I was hoping that there was an easy way to do this.
Here is the code I have,
Calendar cal = new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
String today = (year + "" + (month + 1) + "" + day + "-");
// this will not work for Jan thru June
int length = today.length();
if (length < 9){
today = (year + "" + (month + 1) + "0" + day + "-");
}
System.out.println("Current date : " + today);
Is there an easy way to do this?
Here is the code I have,
Calendar cal = new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
String today = (year + "" + (month + 1) + "" + day + "-");
// this will not work for Jan thru June
int length = today.length();
if (length < 9){
today = (year + "" + (month + 1) + "0" + day + "-");
}
System.out.println("Current date : " + today);
Is there an easy way to do this?