0

Could any one help me on below code, When i try to execute the below code. i am getting the below as a output, Please Correct me to convert same Date. with below format.

current output:

Tue Jan 23 00:05:00 IST 2018

Expected Output:

Tue May 23 00:05:00 IST 2018

public class Testing {

    public static void main(String[] args) throws ParseException {
        String format = "yyyy-mm-dd";
        String date = "2018-05-23";
        Date date2 = new SimpleDateFormat(format).parse(date);
        System.out.println(date2);
    }
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Andrew
  • 1
  • 1
  • 1
    Common problem: `MM` not `mm`. Please [links to similar questions](https://www.google.com/search?q=simpledateformat+not+working+for+month+site:stackoverflow.com) – Hovercraft Full Of Eels Apr 29 '18 at 15:24
  • 3
    Use `yyyy-MM-dd`. `mm` is for minutes – ernest_k Apr 29 '18 at 15:24
  • Thanks alot Ernest Kiwele. It's working Fine. – Andrew Apr 29 '18 at 15:27
  • I recommend you avoid the `SimpleDateFormat` class. It is not only long outdated, it is also notoriously troublesome. Today we have so much better in [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). Which BTW will parse your date string without any explicit formatter. – Ole V.V. Apr 29 '18 at 17:57

0 Answers0