Java 如何将中的日期转换为字符串MM/dd/yyyy格式?
我有一个日期2014-10-01 00:00:00.0 我必须转换为2014年1月10日 我怎么办?试试这个Java 如何将中的日期转换为字符串MM/dd/yyyy格式?,java,date,simpledateformat,date-formatting,Java,Date,Simpledateformat,Date Formatting,我有一个日期2014-10-01 00:00:00.0 我必须转换为2014年1月10日 我怎么办?试试这个 // 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
// 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);
这个怎么样
try
{
String currentDate = "2014-10-01 00:00:00.0";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date tempDate=simpleDateFormat.parse(currentDate);
SimpleDateFormat outputDateFormat = new SimpleDateFormat("dd/MM.YYYY");
System.out.println("Output date is = "+outputDateFormat.format(tempDate));
} catch (ParseException ex)
{
System.out.println("Parse Exception");
}
使用SimpleDataFormat:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format("Your date");
如果您使用JodaTime库,这将非常简单
DateTime dt = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd.YYYY");
String str = fmt.print(dt);
试试这个:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date d = sdf.parse("dd/MM.YYYY");
这样我怎么能提问更多的是给我代码问题。看右边的相关问题。祝你好运你为什么不找一点解决办法呢?这里有一些东西可以帮助你:拉杰什,你的问题解决了吗?是的,它工作了,非常感谢你: