字符串到日期转换返回错误的值 [英] String to Date conversion returning wrong value
本文介绍了字符串到日期转换返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将String转换为Date ...但是返回值是错误的。
I am trying to convert a String into Date... But the return value is wrong.
String startDate = "2013-07-24";
Date date = new Date();
try{
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
date = (Date)formatter.parse(startDate);
System.out.println(date);
}
catch(Exception e){
e.printStackTrace();
}
所需的输出是:
Thu Jul 25 00:00:00 CDT 2013
Thu Jul 25 00:00:00 CDT 2013
但实际输出是:
Fri Jan 25 00:00:00 CST 2013
Fri Jan 25 00:00:00 CST 2013
月份如何从7月变为1月?
How does the month becomes Jan from July?
推荐答案
更改dd的DD;
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
这篇关于字符串到日期转换返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文