views:

188

answers:

3

I have a SimpleDateFormat object that I retrieve from some internationalization utilities. Parsing dates is all fine and good, but I would like to be able show a formatting hint to my users like "MM/dd/yyyy". Is there a way to get the formatting pattern from a SimpleDateFormat object?

+2  A: 

Use toPattern() or toLocalizedPattern() method.

doublep
+2  A: 

SimpleDateFormat.toPattern()

Returns a pattern string describing this date format.

skaffman
Thanks, I guess I didn't look close enough.
D Lawson
+1  A: 
import java.text.SimpleDateFormat;

public class Sdf {
    public static void main( String [] args ) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        String patternToUse = sdf.toPattern();
        System.out.println( patternToUse );
    }
}
OscarRyz