Reputation:
I have an object whose class has a getter method , and this getter method returns a Date value. I want to show this value in a Label in the format DD/MM/YYYY.
How to achieve that with LWUIT ?
Thank you very much indeed
Upvotes: 1
Views: 931
Reputation:
To thank you here is a code of mine which formats a number :
public static String formatNombre(int trivialNombre, String separateur)
{
String pNombre, sNombreLeads, sNombre, argNombre, resultat;
int leadingBits;
int nbBit;
pNombre = String.valueOf(trivialNombre);
if (pNombre.length() > 3)
{
leadingBits = (pNombre.length())%3;
if (leadingBits != 0)
sNombreLeads = pNombre.substring(0, leadingBits).concat(separateur);
else
sNombreLeads = "";
nbBit = 0;
sNombre = "";
argNombre = pNombre.substring(leadingBits);
for (int i=0;i<argNombre.length();i++)
{
sNombre = sNombre.concat(String.valueOf(argNombre.charAt(i)));
nbBit++;
if (nbBit%3 == 0)
sNombre = sNombre.concat(separateur);
}
sNombre = sNombre.substring(0, sNombre.length() - 1);
resultat = sNombreLeads.concat(sNombre);
return resultat;
}
else
return pNombre;
}
Upvotes: 2
Reputation: 14453
You can use this code to convert date to string format and pass the this string value to label.
public static String dateToString (long date)
{
Calendar c = Calendar.getInstance();
c.setTime(new Date(date));
int y = c.get(Calendar.YEAR);
int m = c.get(Calendar.MONTH) + 1;
int d = c.get(Calendar.DATE);
String t = (d<10? "0": "")+d+"/"+(m<10? "0": "")+m+"/"+(y<10? "0": "")+y;
return t;
}
Upvotes: 2