当前位置: 技术问答>java相关
java.text.DateFormat.getDateInstance();格式的问题
来源: 互联网 发布时间:2015-08-28
本文导语: 上面的代码, 结果为 Sep 7, 2002 有些机器是 2002-9-7 怎么统一呀? | caused by computer's local setting. Please read the API: To format a number for a different Locale, specify it in the call to getDateInstance()...
上面的代码,
结果为
Sep 7, 2002
有些机器是
2002-9-7
怎么统一呀?
|
caused by computer's local setting.
Please read the API:
To format a number for a different Locale, specify it in the call to getDateInstance().
DateFormat df = DateFormat.getDateInstance(Locale.US);
Please read the API:
To format a number for a different Locale, specify it in the call to getDateInstance().
DateFormat df = DateFormat.getDateInstance(Locale.US);
|
用SimpleDateFormat:
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar now = new GregorianCalendar();
Date d = now.getTime();
out.println(df1.format(d));
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar now = new GregorianCalendar();
Date d = now.getTime();
out.println(df1.format(d));
|
You do not need to change the system's local setting
Just change to
DateFormat df = DateFormat.getDateInstance(Locale.CN);
Please read the JDK API for more detail.
Just change to
DateFormat df = DateFormat.getDateInstance(Locale.CN);
Please read the JDK API for more detail.
|
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
String adddate=df.format(MyDate.getTime()).substring(0,8);
SimpleDateFormat("yyyyMMdd");这里你可以定义你的输出格式。
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
String adddate=df.format(MyDate.getTime()).substring(0,8);
SimpleDateFormat("yyyyMMdd");这里你可以定义你的输出格式。