Add tags

Add tags to the following comment
Java SE 6の和暦機能を使用しました。
結果は以下のとおりで、太陰暦云々の話でもエラーなしで
出力するところに注意が必要です。

 明治01年 12月 2日
 大正15年 12月 24日
 平成19年 12月 1日
 昭和01年 12月 25日
 明治01年 1月 2日
 明治09年 4月 2日

ちゃんと「範囲外」を出力しなければならないため、
お題を解いたとは言えないのですが、
和暦を使う際には気をつけてくださいねという
意味も込めて投稿の投稿です。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Wareki {

    public static void main(String[] args) throws ParseException {
        System.out.println(convert("1868/12/2"));
        System.out.println(convert("1926/12/24"));
        System.out.println(convert("2007/12/01"));
        System.out.println(convert("1926/12/25"));
        System.out.println(convert("1868/1/2"));
        System.out.println(convert("1868/100/2"));
    }
    
    public static String convert(String dateStr) throws ParseException {
        Locale waLocale = new Locale("ja", "JP", "JP");
        DateFormat sei = new SimpleDateFormat("yyyy/MM/dd");
        Date date = sei.parse(dateStr);
        
        DateFormat wa = new SimpleDateFormat("GGGGyy年 MMMM d日", waLocale);
            
        return wa.format(date);
    }

}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...