How do I get my date time in the correct format while getting the database in the spring and hibernation?

advertisements

I am using spring and hibernate to develop an application.I have used

@Entity
public class Category {
@CreationTimestamp
private java.sql.Timestamp created;
//getter and setter
}

for automatically saving the created time.It saves the created time well in database like:

 2017-03-29 12:19:16

but when I get the json object my date is changed to another format like

"created": 1490769256000

My method for getting a category is:

public Category findCategoryById(int id) throws SQLException {
    session = sessionFactory.getCurrentSession();
    return ((Category)session.get(Category.class,id));
}

How can I get it in the same format like it is saved in the database.


import java.sql.Date;
import java.text.SimpleDateFormat;

public class MainClass {

    public static void main(String[] args) {

        long long_date = 1490769256000L;

        Date dt = new Date (long_date); 

        SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
        System.out.println(sf.format(dt));
    }

}

check main method, by this way you can