Saturday, March 14, 2009

Common Utility methods

1.Convert from Date object to String with given format
/**
* Formats the date object in given format.
* @param aDate the date object
* @param aNewformat the new format
* @return string in new format.
*/
public static String getFormattedDate(Date aDate, String aNewformat)
{
if (aDate != null)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(aNewformat);
String formattedDate = dateFormat.format((aDate));
return formattedDate;
}
return "";
}
2.Convert Calendar To String with given format
/**
* Formats the date object in given format.
* @param aCalendar the date object
* @param aNewformat the new format
* @return string in new format.
*/
public static String getFormattedDate(Calendar aCalendar, String aNewformat) {
//For Ex: aNewformat =dd/mm/yyyy
if (aCalendar != null)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(aNewformat);
String formattedDate = dateFormat.format((aCalendar.getTime()));
return formattedDate;
}
return "";
}
3.Convert Calendar to Date
/**
* Checks calendar object for null and returns date object.
* @param aCalendar the calendar object to check.
* @return Date object or null
*/
public static Date getTime(Calendar aCalendar)
{
if (aCalendar != null)
{
return aCalendar.getTime();
}
return null;
}
You Can Find More on SimpleDateFormat click here

1 comment:

  1. Some UK on-line casinos supply free spins and bonus funds, whereas others only supply one or the other. Although welcome bonuses shouldn’t stand alone as the deciding issue, you may choose a on line casino site based mostly partially on a generous welcome bonus. 카지노 사이트 You want to choose a prime site when playing in} real money games on-line.

    ReplyDelete

AddToAny

Contact Form

Name

Email *

Message *