strange_098
strange_098

Reputation: 1391

How change format date from jDateChooser?

I want enter the start date and the deadline for a task in the database. But the format that saves the database is this: Tue Apr 15 13:46:38 BST 2014 I want in yyyy-MM-dd format.

This is the code I use to write the data in the database:

public void addTask() {
    try {
        Taskt1 = new Task();
        t1.setIdTask(jTIdTask.getText());
        t1.setDescTask(jTDescTask.getText());
        t1.setDate(jDateChooserDare.getDate().toString());
        t1.setdeadline(jDateChooserDeadline.getDate().toString());


        TaskDao dao = new TaskDao();
        dao.Task(t1);

    } catch (SQLException ex) {
        Logger.getLogger(jTTask.class.getName()).log(Level.SEVERE, null, ex);
    }
}

--------------Form-----------

enter image description here

Upvotes: 1

Views: 9551

Answers (1)

Sireesh Yarlagadda
Sireesh Yarlagadda

Reputation: 13736

I hope , you can use SimpleDateFormat for accomplishing this.

Code:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String date = sdf.format(jDateChooserDeadline.getDate());

t1.setDate(date);

Upvotes: 3

Related Questions