简体   繁体   中英

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-----------

在此处输入图片说明

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM