ModelFormField 2000
//DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
/**
* fix china chinese date display
*/
if(locale.equals(Locale.CHINA)||locale.equals(Locale.CHINESE)){
dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
}
UtilDateTime 988
public static DateFormat toDateTimeFormat(String dateTimeFormat, TimeZone tz, Locale locale) {
DateFormat df = null;
if (UtilValidate.isEmpty(dateTimeFormat)) {
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
/**
* fix china chinese date display
*/
if(locale.equals(Locale.CHINA)||locale.equals(Locale.CHINESE)){
df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.MEDIUM, locale);
}
} else {
df = new SimpleDateFormat(dateTimeFormat);
}
df.setTimeZone(tz);
return df;
}
//DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
/**
* fix china chinese date display
*/
if(locale.equals(Locale.CHINA)||locale.equals(Locale.CHINESE)){
dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
}
UtilDateTime 988
public static DateFormat toDateTimeFormat(String dateTimeFormat, TimeZone tz, Locale locale) {
DateFormat df = null;
if (UtilValidate.isEmpty(dateTimeFormat)) {
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
/**
* fix china chinese date display
*/
if(locale.equals(Locale.CHINA)||locale.equals(Locale.CHINESE)){
df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.MEDIUM, locale);
}
} else {
df = new SimpleDateFormat(dateTimeFormat);
}
df.setTimeZone(tz);
return df;
}
本文介绍了一种日期格式处理方法,特别关注于解决中文环境下的显示问题。通过使用Java的DateFormat类,可以根据不同的区域设置调整短日期和日期时间的格式。此外,还提供了一个实用的方法toDateTimeFormat,该方法允许开发者指定日期时间格式字符串、时区和区域设置。
1559

被折叠的 条评论
为什么被折叠?



