How to get the month name from a date in Java

3 Answers

0 votes
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String monthName = LocalDate.of(2013, 2, 27).format(DateTimeFormatter.ofPattern("MMMM"));
        System.out.println(monthName); // February

        monthName = LocalDate.of(2013, 2, 27).format(DateTimeFormatter.ofPattern("MMM"));
        System.out.println(monthName); // Feb
    }
}




/*
run:
 
February
Feb
 
*/

 



answered Jan 7, 2025 by avibootz
0 votes
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {

        LocalDate date = LocalDate.of(2025, 1, 7);

        String monthName = date.getMonth().getDisplayName(TextStyle.FULL, Locale.ENGLISH);

        System.out.println(monthName);
    }
}



/*
run:
 
January
 
*/

 



answered Jan 7, 2025 by avibootz
0 votes
import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {

        LocalDate date = LocalDate.of(2025, 1, 7);
        
        System.out.println(date.getMonth()); 
    }
}



/*
run:
 
JANUARY
 
*/

 



answered Jan 7, 2025 by avibootz

Related questions

1 answer 112 views
1 answer 124 views
1 answer 105 views
1 answer 103 views
2 answers 101 views
1 answer 85 views
1 answer 75 views
...