2 Replies Latest reply: Oct 11, 2008 10:29 PM by 3004 RSS

    European Style Date Converter - mm/dd/yyyy to dd.mm.yy

    843785
      Hi, I am trying to write a program that reads a string for a date in the format mm/dd/yyyy and display it in the typical European format of dd.mm.yy

      For example if the input is 03/13/2004 I'd like the output to appear as 13.03.04. Also I'd like it to use the JOptionPane for I/O.

      Thanks very much!
        • 1. Re: European Style Date Converter - mm/dd/yyyy to dd.mm.yy
          843785
          alex_t88 wrote:
          Hi, I am trying to write a program that reads a string for a date in the format mm/dd/yyyy and display it in the typical European format of dd.mm.yy
          SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy");
          SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

          I'll leave the rest for you. Check out parse and format methods, and read the javadocs.
          • 2. Re: European Style Date Converter - mm/dd/yyyy to dd.mm.yy
            3004
            There are two main approaches that pop to mind:

            1) Use two SimpleDateFormats, one to parse the original String into a Date, and the other to format that Date into a String in the desired format.

            2) Just use String.replaceAll to reformat it, since the new string will have the same components in a different order, +/- some constants.