Here you can find the source of format(String pattern, Object value)
private static String format(String pattern, Object value)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import javax.swing.text.MaskFormatter; public class Main { private static String format(String pattern, Object value) { MaskFormatter mask;/*from w ww .ja va 2 s.co m*/ try { mask = new MaskFormatter(pattern); mask.setValueContainsLiteralCharacters(false); return mask.valueToString(value); } catch (ParseException e) { throw new RuntimeException(e); } } }