Various date format conversions


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GeneralUtil {

//Date Time Util
public static Timestamp getTimeStamp(String date) throws ParseException {
String DATE_FORMAT = "MM-dd-yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
Date today = dateFormat.parse(date);
Timestamp t1 = new Timestamp(today.getTime());
return t1;
}

public static String getCurrentDateTime(String format) {
DateFormat dateFormat = new SimpleDateFormat(format);
Date date = new Date();
return dateFormat.format(date);
}

public static String getDateMMDDYYY(Timestamp timestamp) {
String dateStr = "";

dateStr = timestamp.toString().substring(0, 10);
return dateStr;
}

public static String getDateFromDBStringMMDDYYYY(String theDate) {
String strOutDt = "";
try {
Date dtTmp = new SimpleDateFormat("yyyy-MM-dd").parse(theDate);
strOutDt = new SimpleDateFormat("MM-dd-yyyy").format(dtTmp);
} catch (ParseException pe) {
}
return strOutDt;
}

// public static void main(String[] args) throws ParseException {
//
public static String getDateFromTimeStamp(Timestamp t) {
String result = "";
try {
Timestamp dateTime = (Timestamp) t;

SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
result = dateFormat.format(dateTime);
return result;
} catch (Exception exception) {
}
return result;

}

public static String getDBDateFormat(String dateStr) {
String result = "";
try {
Date dtTmp = new SimpleDateFormat("MM-dd-yyyy").parse(dateStr);
result = new SimpleDateFormat("yyyy-MM-dd").format(dtTmp);
return result;
} catch (Exception exception) {
}
return result;

}

public static double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d));
}
//End Date Time Util

public static void main(String[] args) throws ParseException {
String str = "11-24-2010";

}
}