how-to

Conversion between types

How to convert date to string

For this example you need to use:

import java.text.*;

For conversion is used SimpleDateFormat class, that specifies used date mask.

/* - value for conversion (current date) */

Date d = Calendar.getInstance().getTime();

/* - specify format mask */

DateFormat df = new SimpleDateFormat( "dd.MM.yyyy" );

/* - convert */

String s = df.format( d );

/* - print result */

System.out.println( s );
The output is:
09.10.2012