Convert Date To String and String to Date

String datestring1 = "2009-10-27 14:36:59.580250";
Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(datestring1);
String datestring2 = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date1);

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class DateHelper {
	private static Logger logger = Logger.getLogger(DateHelper.class);

	public static Date strToDate(String _strDate, String _pattern)
			throws ParseException {
		Date date;
		try {
			date = new SimpleDateFormat(_pattern).parse(_strDate);
			logger.debug("date converted");
			return date;
		} catch (ParseException e) {
			logger.error(e.getMessage(), e);
			throw e;

	public static String dateToString(Date date, String _pattern) {
		String strDate;

		strDate = new SimpleDateFormat(_pattern).format(date);
		logger.debug("date converted" + strDate);
		return strDate;