Formatting month using SimpleDateFormat
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));
sdf = new SimpleDateFormat("MM");
System.out.println("Current Month in MM format : " + sdf.format(date));
sdf = new SimpleDateFormat("MMM");
System.out.println("Current Month in MMM format : " + sdf.format(date));
sdf = new SimpleDateFormat("MMMM");
System.out.println("Current Month in MMMM format : " + sdf.format(date));
}
}
The output:
Current Month in M format : 11
Current Month in MM format : 11
Current Month in MMM format : Nov
Current Month in MMMM format : November
Home
Java Book
Essential Classes
Java Book
Essential Classes
SimpleDateFormat:
- SimpleDateFormat class introduction
- SimpleDateFormat formats date, day,
- Add AM PM to time format using SimpleDateFormat
- Formatting date in default formats using DateFormat
- Formatting day using SimpleDateFormat
- Formatting day of week using SimpleDateFormat
- Formatting hour using SimpleDateFormat
- Formatting hour using SimpleDateFormat: k
- Formatting Minutes using SimpleDateFormat
- Formatting month using SimpleDateFormat
- Formatting seconds using SimpleDateFormat
- Formatting TimeZone using SimpleDateFormat
- Formatting year using SimpleDateFormat
- Use various format
- Convert date string from one format to another format using SimpleDateFormat