android 将字符串解析为日期 - 日期不正确
android parse string to date - incorrect date
我花了很多时间,但我仍然不明白为什么会这样。在下面的代码中,时间更改正确,日期不正确。
String dtAll = mDate + " " + mTime;
Date dat = new Date();
@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("dd/MM/YYYY HH:mm");
try {
dat = format.parse(dtAll);
} catch (ParseException e) {
e.printStackTrace();
}
Log.d("dat", String.valueOf(dat));
Log.d("dtAll", dtAll);
结果:
D/dat: Sun Dec 31 17:24:00 GMT+01:00 2017
D/dtAll: 20/09/2018 17:24
有人愿意帮助我吗?
使用格式 yyyy
:
中的年份
new SimpleDateFormat("dd/MM/yyyy HH:mm");
我花了很多时间,但我仍然不明白为什么会这样。在下面的代码中,时间更改正确,日期不正确。
String dtAll = mDate + " " + mTime;
Date dat = new Date();
@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("dd/MM/YYYY HH:mm");
try {
dat = format.parse(dtAll);
} catch (ParseException e) {
e.printStackTrace();
}
Log.d("dat", String.valueOf(dat));
Log.d("dtAll", dtAll);
结果:
D/dat: Sun Dec 31 17:24:00 GMT+01:00 2017
D/dtAll: 20/09/2018 17:24
有人愿意帮助我吗?
使用格式 yyyy
:
new SimpleDateFormat("dd/MM/yyyy HH:mm");