Help us understand the problem. What is going on with this article?

SimpleDateFormatの月表記、曜日表記をカスタマイズする。

More than 3 years have passed since last update.

SimpleDateFormatを使って曜日とか(Monday,Tuesday)をオリジナル表記したい時メモ。
DateFormatSymbols(Javadoc7)が文字列リソースを管理しているクラスなので、このプロパティweekdaysとかを上書きすればok
javadocを参考にDateFormatSymbolsを上書きしてみる。

標準で設定されるweekdaysを出力する。

Main.java
        DateFormatSymbols dfs = DateFormatSymbols.getInstance(Locale.ENGLISH);
        String[] weeks = dfs.getWeekdays();

        int i = 0;
        for(String week:weeks){
            System.out.println( i + " :" + week);
            i++;
        }

実行結果

0 :
1 :Sunday
2 :Monday
3 :Tuesday
4 :Wednesday
5 :Thursday
6 :Friday
7 :Saturday

0番目の要素が空なのはCalenderの定数を使用しているから?

weekdaysを上書きしてみる

Main.java
        DateFormatSymbols dfs = DateFormatSymbols.getInstance(Locale.ENGLISH);
        String[] newWeek = {
                "","sunday","monday","tuesday","wedesday","thursday","friday","saturday"
        };
        dfs.setWeekdays(newWeek);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEEE",dfs);
        String now = sdf.format(new Date());

        System.out.println(now);

実行結果

2016-03-22 20:29:29 tuesday
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした