Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2012 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/3656792 to your computer and use it in GitHub Desktop.
Save anonymous/3656792 to your computer and use it in GitHub Desktop.
和暦の毎年の日数を出力するプログラム
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