简体   繁体   中英

change Month format from jDateChooser

how to change month format in jDateChooser ? this is my code :

    private DateFormat df = DateFormat.getDateInstance();

    private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) { 
            String x = df.format(jDateChooser.getDate());
            showtable(x); // this method for showing Date to jTable 
    }

example output : 04 Mar 15, and I want to change Month name "Mar" to "03", but don't know how to change it. Please help

Use the SimpleDataFormat class instead

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Replace this

private DateFormat df = DateFormat.getDateInstance();

with this

private SimpleDateFormat df = SimpleDateFormat("dd MM yy");

You can customise any format you want here

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