TCM
TCM

Reputation: 16920

Time not entered in mysql ? Java

I have a datetime field in mysql table and i am using JPA for persisting data but only date goes in database. Time always shows 00:00:00. What should i do?

I am not doing any manipulation with Date. All i do is to assign new Date() to a variable and store it in database.

What am i doing wrong?

Upvotes: 1

Views: 87

Answers (2)

VoodooChild
VoodooChild

Reputation: 9784

Example below:

private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }

Tips like these can be found on http://www.java-tips.org

Upvotes: 1

Chris Lercher
Chris Lercher

Reputation: 37798

Use the annotation @Temporal(TemporalType.TIMESTAMP)

Upvotes: 2

Related Questions