Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
和暦の毎年の日数を出力するプログラム
package org.mericle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
public class JapaneseDayCounter {
public static void main(String[] args) {
ArrayList<String> messages = new ArrayList<String>();
// JRE標準の和暦を使う
Locale locale = new Locale("ja", "JP", "JP");
DateFormat format = new SimpleDateFormat("GGGGyy年", locale);
Calendar calendar = Calendar.getInstance(locale);
for (calendar.set(24, 11, 31) // 平成24年12月31日
; calendar.get(Calendar.ERA) != 0
; calendar.set(Calendar.DAY_OF_YEAR, 1),
calendar.add(Calendar.DAY_OF_YEAR, -1)) {
messages.add(format.format(calendar.getTime())
+ ""
+ calendar.get(Calendar.DAY_OF_YEAR)
+ "日です。");
}
// 平成~明治の順を明治~平成に直して出力する
for (int i = messages.size() - 1; i >= 0; --i) {
System.out.println(messages.get(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.