语言环境的 Java 日期格式
如何找到给定 Locale 的 DateFormat?
How can I find the DateFormat for a given Locale?
推荐答案
DateFormat.getDateInstance(int,Locale)
例如:
import static java.text.DateFormat.*;
DateFormat f = getDateInstance(SHORT, Locale.ENGLISH);
那么就可以使用这个对象来格式化Dates:
Then you can use this object to format Dates:
String d = f.format(new Date());
如果你真的想知道底层模式(例如 yyyy-MMM-dd),那么你会得到一个 SimpleDateFormat 对象:
If you actually want to know the underlying pattern (e.g. yyyy-MMM-dd) then, as you'll get a SimpleDateFormat object back:
SimpleDateFormat sf = (SimpleDateFormat) f;
String p1 = sf.toPattern();
String p2 = sf.toLocalizedPattern();
相关文章