Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210829] (Java) Convert String month to Integer month #201

Open
JuHyun419 opened this issue Aug 29, 2021 · 0 comments
Open

[20210829] (Java) Convert String month to Integer month #201

JuHyun419 opened this issue Aug 29, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

문자열 형식의 Month를 숫자로 변환

  • "Jan" => 1, "Feb" => 2 ... "Aug" => 8
    private String getFormatMonth(final String month) {
        DateTimeFormatter parser = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH);
        TemporalAccessor accessor = parser.parse(month);
        String formatMonth = String.valueOf(accessor.get(ChronoField.MONTH_OF_YEAR));
        return formatMonth;
    }

    System.out.println(getFormatMonth("Dec")); // 12
    12
  • 달력에 존재하지 않는 문자열이 입력될 경우 예외
System.out.println(getFormatMonth("Des"))

image

@JuHyun419 JuHyun419 added the Java label Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant