区域设置的Java日期格式
问题描述:
如何查找给定的 Locale
的 DateFormat
?
答
DateFormat.getDateInstance(int,Locale)
例如:
import static java.text.DateFormat.*;
DateFormat f = getDateInstance(SHORT, Locale.ENGLISH);
然后可以使用此对象格式化 Date
s:
Then you can use this object to format Date
s:
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();