Here you can find the source of dateToStringWithPattern(Date date, String pattern)
public static String dateToStringWithPattern(Date date, String pattern)
//package com.java2s; /*/*w ww . j a v a2s .com*/ * Copyright (C) 2010 Viettel Telecom. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String dateToStringWithPattern(Date date, String pattern) { try { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(date); } catch (Exception e) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); return sdf.format(date); } } }