Convert date from date to any date using below function
public static String convertDate(String date, String fromFormat,
String toFormat)
{
String formattedDate = "";
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(fromFormat);
Date d = simpleDateFormat.parse(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
simpleDateFormat = new SimpleDateFormat(toFormat);
simpleDateFormat.setCalendar(calendar);
formattedDate = simpleDateFormat.format(calendar.getTime());
} catch (Exception e) {
if (e != null)
e.printStackTrace();
}
return formattedDate;
}
now you can use this function like below
//for example :-mydate = 12/01/2000
String mydate = convertDate("mydate", "MM/dd/yyyy", "dd MMMM yyyy");
public static String convertDate(String date, String fromFormat,
String toFormat)
{
String formattedDate = "";
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(fromFormat);
Date d = simpleDateFormat.parse(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
simpleDateFormat = new SimpleDateFormat(toFormat);
simpleDateFormat.setCalendar(calendar);
formattedDate = simpleDateFormat.format(calendar.getTime());
} catch (Exception e) {
if (e != null)
e.printStackTrace();
}
return formattedDate;
}
now you can use this function like below
//for example :-mydate = 12/01/2000
String mydate = convertDate("mydate", "MM/dd/yyyy", "dd MMMM yyyy");
No comments:
Post a Comment
Comments