java.util.Date.toString() is printing out wrong format

Posted by pacoverflow on Stack Overflow See other posts from Stack Overflow or by pacoverflow
Published on 2012-11-27T23:03:01Z Indexed on 2012/11/27 23:03 UTC
Read the original article Hit count: 240

Filed under:
|

The following code prints out "vmtDataOrig.creationdate=2012-11-03"

VmtData vmtDataOrig = VmtDataDao.getInstance().loadVmt(1);
System.out.println("vmtDataOrig.creationdate=" + vmtDataOrig.getCreationDate().toString());

Here is the definition of the creationDate field in the VmtData class:

private Date creationDate = null;

Here is the hibernate mapping of the creationDate field to the database table column:

<property name="creationDate" column="CREATIONDATE" type="date"/>

The CREATIONDATE column in the MySQL database table is of type "date", and for the record retrieved it has the value "2012-11-03".

The Javadoc for the java.util.Date.toString() method says it is supposed to print the Date object in the form "dow mon dd hh:mm:ss zzz yyyy". Anyone know why it is printing it out in the form "yyyy-MM-dd"?

© Stack Overflow or respective owner

Related posts about date

Related posts about tostring