Here you can find the source of convertDateToString(Date date, String pattern)
public static String convertDateToString(Date date, String pattern)
//package com.java2s; /*/*from w w w . java 2 s.co m*/ * Copyright (C) 2010 dungnv. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * * @param date to convert * @return String * @throws Exception if error */ public static String convertDateToString(Date date) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); if (date == null) { return ""; } try { return dateFormat.format(date); } catch (Exception e) { throw e; } } public static String convertDateToString(Date date, String pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); if (date == null) { return ""; } try { return dateFormat.format(date); } catch (Exception e) { e.printStackTrace(); return ""; } } }