Created
October 23, 2014 05:41
-
-
Save syobochim/732975c1520fc1bd3fa7 to your computer and use it in GitHub Desktop.
西暦を和暦に変換する(1月1日の年号を取得)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.chrono.JapaneseDate; | |
import java.time.format.DateTimeFormatter; | |
import java.util.Locale; | |
public class changeYear { | |
public static void main(String[] args) { | |
System.out.println(changeYearToEra(2014)); | |
System.out.println(changeYearToEra(1989)); | |
System.out.println(changeYearToEra(1990)); | |
} | |
public static String changeYearToEra(int year) { | |
JapaneseDate japaneseDate = JapaneseDate.of(year, 1, 1); | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("Gy年", Locale.JAPANESE); | |
return formatter.format(japaneseDate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment