Why is my date not displaying properly?
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.
One thing is parsing and another thing is formatting.
Check this example in order to display the formatted string.
@Test
public void testDateFormat() throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
Date myDate = df.parse("2011/11/11 11:11:11");
System.out.println(df.format(myDate));
}
Output:
2011/11/11 11:11:11
What do you want to achieve? You have successfully parsed "2011/11/11 11:11:11"
String
into java.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 to String
, use df.format()
which does the opposite thing compared to df.parse()
.
精彩评论