简体   繁体   中英

how to display date chosen from java JXDatePicker and how to stored into database?

i have a code like this

    JXDatePicker picker = new JXDatePicker();
    //picker.setDate(Calendar.getInstance().getTime());
    picker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
    picker.setDate(Calendar.getInstance().getTime());
    picker.setBounds(50,130,100,25);
    f.add(picker);

now i want to display date into console how to do this?

For displaying date into console you can do the following:

SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
picker.setFormats(formatter);
System.out.println(formatter.format(picker.getDate()));

But as @AndrewThompson said, in GUI application, displaying date on console is a bad idea. Instead you can show it in a JLabel if you want.

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