字符串到目前为止的Java转换

时间:2013-11-14 03:25:28

标签: java

我有这段代码

SimpleDateFormat ft = new SimpleDateFormat ("dd/MM/yyyy");
String sDate="2013-11-13";
String formattedDate=ft.format( ft.parse(sDate));

但这不起作用。任何帮助

2 个答案:

答案 0 :(得分:7)

您需要更改此日期格式

SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");

修改

评论问题:但我需要dd / mm / yyyy格式吗?

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2013-11-13");
String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(date);
System.out.println(formattedDate);

答案 1 :(得分:2)

将SimpleDate格式更改为以下,并且它将起作用

SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
相关问题