发布日期:2018-03-26
如何将java.util.Date转换为String类型?+ 查看更多
如何将java.util.Date转换为String类型?
+ 查看更多
发布日期:2018-03-08 17:33
分类:JAVA
浏览次数:128
在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);