集册 Java实例教程 更改日期格式的符号

更改日期格式的符号

欢马劈雪     最近更新时间:2020-01-02 10:19:05

563
更改日期格式的符号
/*
N o  w  J a v a . c o m - 时  代  Java
*/

import java.util.*;

import java.text.*;


public class DateFormatSymbolsDemo {


    static public void changeWeekDays() {


        Date today;

        String result;

        SimpleDateFormat formatter;

        DateFormatSymbols symbols;

        String[] defaultDays;

        String[] modifiedDays;


        symbols = new DateFormatSymbols(new Locale("en", "US"));

        defaultDays = symbols.getShortWeekdays();


        for (int i = 0; i < defaultDays.length; i++) {

            System.out.print(defaultDays[i] + "  ");

        }

        System.out.println();/*时   代     Java  公  众  号 - nowjava.com 提供*/


        String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU",

                "FRI", "SAT" };

        symbols.setShortWeekdays(capitalDays);


        modifiedDays = symbols.getShortWeekdays();

        for (int i = 0; i < modifiedDays.length; i++) {

            System.out.print(modifiedDays[i] + "  ");

        }


        System.out.println();

        System.out.println();


        formatter = new SimpleDateFormat("E", symbols);

        today = new Date();

        result = formatter.format(today);

        System.out.println("Today's day of the week: " + result);

    }


    static public void main(String[] args) {

        changeWeekDays();

    }

}


展开阅读全文