-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplayMonth.java
More file actions
33 lines (27 loc) · 896 Bytes
/
DisplayMonth.java
File metadata and controls
33 lines (27 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.javamultiplex.datetime;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
//How to display month in different formats?
public class DisplayMonth {
public static void main(String[] args) {
Date date=new Date();
DateFormat monthFormat=null;
String month=null;
/*
* M -> Month in digits(1-12)
* MM -> Month in digits(1-12)
* MMM -> Month name in 3 chars
* MMMM -> Full month name
*/
monthFormat=new SimpleDateFormat("M");
month=monthFormat.format(date);
System.out.println("Current month in digits : "+month);
monthFormat=new SimpleDateFormat("MMM");
month=monthFormat.format(date);
System.out.println("Month name in 3 chars : "+month);
monthFormat=new SimpleDateFormat("MMMM");
month=monthFormat.format(date);
System.out.println("Full month name : "+month);
}
}