-3

I tried to get the current date in a specific format, but instead of the month got minutes

import java.text.SimpleDateFormat;
import java.util.Calendar;


public class CurrentDate {

    public static String currentDate() {
    String timeStamp = new SimpleDateFormat("mm/dd/yyyy").format(Calendar.getInstance().getTime());
    return timeStamp;
    }

    public static void main (String [] args) {
        System.out.println(currentDate());
    }

}

Why this code gives minutes ... i tried mon ... ???

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
Andrei Vasilev
  • 597
  • 5
  • 18
  • 37

2 Answers2

6

You want "MM/dd/yyyy" in the SimpleDateFormat. If you look at the documentation at http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html you'll see that lower case m always means minutes, and capital M is month.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
2

SimpleDateFormat:

m for minutes M for Month

kosa
  • 65,990
  • 13
  • 130
  • 167