为什么我的日期显示不正确?
我使用了 SimpleDateFormat:
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
value.adStartDate = df.parse("2011/11/11 11:11:11");
我希望日期会像我提供的字符串一样输出,但我得到的是这样的:
Fri Nov 11 2011 11:11:11 GMT-0500 (Eastern Standard Time)
这显示在我使用 Javascript 创建的表单上...
有没有办法“强制”输出形式就像字符串一样?
基本上我想将格式为“yyyy/MM/dd hh:mm:ss”的日期传递给使用Javascript生成的表单,并让表单以相同的格式显示它。
I used SimpleDateFormat:
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
value.adStartDate = df.parse("2011/11/11 11:11:11");
I was hoping the date would come out like the string I provided, but instead I am getting this:
Fri Nov 11 2011 11:11:11 GMT-0500 (Eastern Standard Time)
This is showing on a form that I created using Javascript...
Is there a way to "force" the output on the form to be like the string?
Basically I want to pass a date with format "yyyy/MM/dd hh:mm:ss" to a form that was generated using Javascript and have the form display it in that same format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一件事是解析,另一件事是格式化。
检查此示例以显示格式化的字符串。
输出:
One thing is parsing and another thing is formatting.
Check this example in order to display the formatted string.
Output:
你想实现什么目标?您已成功将
"2011/11/11 11:11:11"
String
解析为java.util.Date
对象。Date.toString()
生成您看到的字符串(Fri Nov 11 2011 11:11:11 GMT-0500(东部标准时间))。如果您现在想要将
Date
对象格式化回String
,请使用df.format()
,与相比,它执行相反的操作df.parse()。
What do you want to achieve? You have successfully parsed
"2011/11/11 11:11:11"
String
intojava.util.Date
object.Date.toString()
yields the string you see (Fri Nov 11 2011 11:11:11 GMT-0500 (Eastern Standard Time)).If you now want to format the
Date
object back toString
, usedf.format()
which does the opposite thing compared todf.parse()
.