不同区域的星期格式
不同国家的星期的简称或全称有很大的不同。如果想用特定地区的星期格式来表示日期中的星期,可以用format的重载方法:
format(Locale locale, 格式化模式,日期列表);
Locale类的static常量都是Locale常量都是Locale对象。
代码展示如下所示:
import java.util.Date; import java.util.Locale; public class Test01 { public static void main(String[] args) { // TODO Auto-generated method stub String str = String.format(Locale.US, "%ta(%<tF)", new Date()); System.out.println(str); str = String.format(Locale.JAPAN, "%tA(%<tF)", new Date()); System.out.println(str); str = String.format("%tF %<tT", new Date()); System.out.println(str); } }
运行结果如下所示:
代码中%tF等价于"%tY-%tm-%td"。
%tR等价于%tH:%tM
%tT等价于%tH:%tM:%S
%tr等价于%tI:%tM:%tS%TP
%tD等价于%tm/%td/%ty。
%tF等价于"%tY-%tm-%td"。
%tc等价于"%ta %tb %td %tT %tZ %tY.