I have a jformattedtextfield when i put date in this format "ddMMyyyy". I want when lost focus jformattedtextfield, it becames and shows "dd-mm-yyyy". How i can do this???
Asked
Active
Viewed 7,715 times
1
-
Possible duplicate of http://stackoverflow.com/questions/18480633/java-util-date-format-conversion-yyyy-mm-dd-to-mm-dd-yyyy – Dark Knight Mar 23 '16 at 10:22
-
11) add focus listener on the textfield 2) place a code in this listener which willl reformat textfield's value on every focus change with the help of SimpleDateFormat – Cootri Mar 23 '16 at 10:22
1 Answers
2
See the below code:
SimpleDateFormat format1 = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yy");
Date date = format1.parse("05011999");
System.out.println(format2.format(date));

Sumit Singh
- 15,743
- 6
- 59
- 89