3 Replies Latest reply: Oct 18, 2012 4:38 AM by 946388 RSS

    date ,month

    967161
      what is the syntax to only extract date and month from a given date eg"20/03/2012"???
        • 1. Re: date ,month
          sabre150
          Check the Javadoc for class java.text.SimpleDateFormat .
          • 2. Re: date ,month
            rp0428
            >
            what is the syntax to only extract date and month from a given date eg"20/03/2012"???
            >
            Any time you have a question about basics you will liikely find a section in The Java Tutorials that deals with it.

            See the 'Dates and Times' section in the tutorial
            http://docs.oracle.com/javase/tutorial/i18n/format/dateintro.html

            The link of that page to 'Customizing Formats' covers the SimpleDateFormat that sabre150 mentioned.
            http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html

            And that page has an example and source code for the 'SimpleDateFormatDemo'.

            The Java API provides the actual specifications
            http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
            • 3. Re: date ,month
              946388
              Date now = new Date();
                   String datetimeStr = now.toString();
                   System.out.println("1. " + datetimeStr);
                   SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
                   System.out.println("2. " + format.format(now));

              output:

              *1. Thu Oct 18 15:07:17 IST 2012*
              *2. 18/10/2012*

              [How to Use SimpleDateFormat Class Formating/Parsing Date and Time?|http://www.xyzws.com/Javafaq/how-to-use-simpledateformat-class-formating-parsing-date-and-time/142]