Format month in M format like 1,2 etc in Java

Description

The following code shows how to format month in M format like 1,2 etc.

Example


/*  w  w w.  ja va 2 s  . c om*/
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    Date date = new Date();

    
    SimpleDateFormat sdf = new SimpleDateFormat("M");
    System.out.println("Current Month in M format : " + sdf.format(date));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone