Here you can find the source of dataFormatada(Calendar cal)
public static String dataFormatada(Calendar cal)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.swing.text.MaskFormatter; public class Main { public static String dataFormatada(Calendar cal) { SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); return format1.format(cal.getTime()); }/*from www . ja v a 2s . co m*/ private static String format(String pattern, Object value) { MaskFormatter mask; try { mask = new MaskFormatter(pattern); mask.setValueContainsLiteralCharacters(false); return mask.valueToString(value); } catch (ParseException e) { throw new RuntimeException(e); } } }