new*_*bie 26 java formatting locale date
我需要将日期格式化为具有多种语言的应用程序,格式化日期的最佳方式是什么,因为每个国家/地区都有不同类型的日期格式,因此可以按区域设置格式化日期吗?
Boz*_*zho 59
是的,使用DateFormat.getDateInstance(int style,Locale aLocale) 这将以特定于语言环境的方式显示当前日期.
所以,例如:
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, yourLocale);
String formattedDate = df.format(yourDate);
Run Code Online (Sandbox Code Playgroud)
请参阅该文档的样式参数的确切含义(SHORT,MEDIUM,等)
lau*_*ura 13
SimpleDateFormat有一个构造函数,它接受了语言环境,你试过吗?
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
就像是
new SimpleDateFormat("your-pattern-here", Locale.getDefault());