0

Wrote Below Code in Android Java File to fetch Only Date which m getting but issue is not getting correct Month in my given format.

First m fetching current month as Bill Date. Second m fetching Current month + 1 as Due Date.

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");

                Calendar cal = Calendar.getInstance();
            String billdate= dateFormat.format(cal.getTime()).toString();
                cal.add(Calendar.MONTH,1);
                String duedate= dateFormat.format(cal.getTime()).toString();

Output:

22-42-2018 22-42-2018

Can't identify month. Anyone please resolve the query why m not getting exact month and what changes should i make.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Umang
  • 90
  • 9
  • 2
    Use `SimpleDateFormat dateFormat=new SimpleDateFormat("dd-MM-yyyy");` . m is for minute , M is for month in year . Read [SimpleDateFormat](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html). – ADM Apr 22 '18 at 09:39
  • FYI, the troublesome old date-time classes such as `java.util.Date`, `java.util.Calendar`, and `java.text.SimpleDateFormat` are now legacy, supplanted by the [*java.time*](https://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html) classes. Much of the *java.time* functionality is back-ported to Java 6 & Java 7 in the [***ThreeTen-Backport***](http://www.threeten.org/threetenbp/) project. Further adapted for earlier Android in the [***ThreeTenABP***](https://github.com/JakeWharton/ThreeTenABP) project. See [*How to use ThreeTenABP…*](http://stackoverflow.com/q/38922754/642706). – Basil Bourque Jun 07 '18 at 02:28

0 Answers0