java.util.Dateを文字列に変換

Javaでjava.util.DateオブジェクトをStringに変換したいのですが。

フォーマットは 2010-05-30 22:15:52 です。

ソリューション

DateFormat#format`][1]メソッドを使用して、DateStringに変換します。

String pattern = "MM/dd/yyyy HH:mm:ss";

// Create an instance of SimpleDateFormat used for formatting 
// the string representation of date according to the chosen pattern
DateFormat df = new SimpleDateFormat(pattern);

// Get the today date using Calendar object.
Date today = Calendar.getInstance().getTime();        
// Using DateFormat format method we can create a string 
// representation of a date with the defined format.
String todayAsString = df.format(today);

// Print the result!
System.out.println("Today is: " + todayAsString);

From http://www.kodejava.org/examples/86.html

[1]: https://docs.oracle.com/javase/9/docs/api/java/text/DateFormat.html#format-java.util.Date-

解説 (8)
Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = formatter.format(date);
解説 (1)

SimpleDateFormat](http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)を探しているようです

形式:yyyy-MM-dd kk:mm:ss

解説 (6)