将java.util.Date转换为String

问题:

我想在Java中将java.util.Date对象转换为String
格式为2010-05-30 22:15:52

回答:

在Java中,使用格式字符串将日期转换为字符串:

// Create an instance of SimpleDateFormat used for formatting 
// the string representation of date (month/day/year)
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

// Get the date today 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 reportDate = df.format(today);

// Print what date is today!
System.out.println("Report Date: " + reportDate);

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

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: Convert java.util.Date to String

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

35 + = 36