【发布时间】:2016-08-15 14:12:56
【问题描述】:
我在字符串对象中有日期。我想转换成 Date 对象。
Date getDateFmString(String dateString)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date convertedCurrentDate = sdf.parse(dateString);
return convertedCurrentDate ;
}
above 函数返回以下输出。
Fri Apr 22 00:00:00 IST 2016
- 但我只想以“2016-03-01”这种格式输出
- 函数只能接受字符串。
- 函数应该返回 Date 对象。
【问题讨论】:
-
不是已经是正确的格式了吗?
-
这是在字符串对象中我想要在日期对象中
-
但是为了什么目的?是验证字符串的格式吗?
-
我必须编写一个函数,该函数接受字符串并以 dd-MM-YYYY 格式返回 Date 对象
标签: java date date-formatting