我有一个“2013-09-18”形式的字符串。我想将它转换成 java.util.Date。 我在做这个
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date convertedCurrentDate = sdf.parse(currentDateText);
convertedCurrentDate 即将到来 'Wed Sep 18 00:00:00 IST 2013'
我希望我的输出格式为“2013-09-18”
时、分、秒不应出现,应采用 yyyy-MM-dd 的形式。
最佳答案
您可能需要按如下所示格式化
输出。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date convertedCurrentDate = sdf.parse("2013-09-18");
String date=sdf.format(convertedCurrentDate );
System.out.println(date);
使用
String convertedCurrentDate =sdf.format(sdf.parse("2013-09-18"));
输出:
2013-09-18
关于java - 以 (yyyy-MM-dd) 格式解析字符串日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18873014/