4 Replies Latest reply: Sep 25, 2007 1:23 PM by 807600 RSS

    How to get ISO date format?

    807600
      Hi there,

      I'm having problem converting date to ISO format. How do I convert a date in the form of "Tue Sep 25 10:18:59 PDT 2007" to "20070925101859" ? Basically I am trying to get the date in "yyyymmddhhmmss". Below is my code, I keep getting "Tue Sep 25 10:18:59 PDT 2007", please help:

      beginDateAsDate = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddhhmmss");
      sdf.format( beginDateAsDate );
      endDateAsDate = beginDateAsDate;
      Calendar c1 = Calendar.getInstance();
      c1.setTime(beginDateAsDate);
      c1.add(Calendar.YEAR,2);
      endDateAsDate = c1.getTime();

      System.out.println("Begin Date is: " beginDateAsDate.toString());+
      System.out.println("End Date is: " endDateAsDate.toString());          +

      Output:
      Begin Date is: Tue Sep 25 10:18:59 PDT 2007
      End Date is: Fri Sep 25 10:18:59 PDT 2009