在Android中将yyyy-MM-DD字符串解析为日期yyyy-MM-DD?

nis*_*tan -1 java android simpledateformat

String startDateStr = "2017-02-03"
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD",Locale.US);
Date date = (Date)formatter.parse(startDateStr);    
Run Code Online (Sandbox Code Playgroud)

2017-02-03日期解析为Tue Jan 03 00:00:00 GMT+05:45 2017

我错过了什么?

更新

我需要将一个字符串转换为日期对象,同时保持相同的格式。

这样做的原因是我想利用public boolean after(Date when)方法

Cha*_*ruක 5

这会起作用^_^

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
DateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
String startDateStr ="2017-02-03";
Date date = null;
try {
    date = inputFormat.parse(startDateStr);
    String startDateStrNewFormat = outputFormat.format(date);
} catch (ParseException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

对你的输出的一些解释:

D是一年中的某天 (1-365)
d是一月中的某天 (1-31)

检查文件

在此输入图像描述