本文整理汇总了Java中com.ibm.icu.text.DateFormat.setCalendar方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.setCalendar方法的具体用法?Java DateFormat.setCalendar怎么用?Java DateFormat.setCalendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.setCalendar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatHelper
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
static private DateFormat formatHelper(Calendar cal, ULocale loc, int dateStyle,
int timeStyle) {
if (timeStyle < DateFormat.NONE || timeStyle > DateFormat.SHORT) {
throw new IllegalArgumentException("Illegal time style " + timeStyle);
}
if (dateStyle < DateFormat.NONE || dateStyle > DateFormat.SHORT) {
throw new IllegalArgumentException("Illegal date style " + dateStyle);
}
PatternData patternData = PatternData.make(cal, loc);
String override = null;
// Resolve a pattern for the date/time style
String pattern = null;
if ((timeStyle >= 0) && (dateStyle >= 0)) {
pattern = SimpleFormatterImpl.formatRawPattern(
patternData.getDateTimePattern(dateStyle), 2, 2,
patternData.patterns[timeStyle],
patternData.patterns[dateStyle + 4]);
// Might need to merge the overrides from the date and time into a single
// override string TODO: Right now we are forcing the date's override into the
// time style.
if ( patternData.overrides != null ) {
String dateOverride = patternData.overrides[dateStyle + 4];
String timeOverride = patternData.overrides[timeStyle];
override = mergeOverrideStrings(
patternData.patterns[dateStyle+4],
patternData.patterns[timeStyle],
dateOverride, timeOverride);
}
} else if (timeStyle >= 0) {
pattern = patternData.patterns[timeStyle];
if ( patternData.overrides != null ) {
override = patternData.overrides[timeStyle];
}
} else if (dateStyle >= 0) {
pattern = patternData.patterns[dateStyle + 4];
if ( patternData.overrides != null ) {
override = patternData.overrides[dateStyle + 4];
}
} else {
throw new IllegalArgumentException("No date or time style specified");
}
DateFormat result = cal.handleGetDateFormat(pattern, override, loc);
result.setCalendar(cal);
return result;
}
示例2: formatCalDateTime
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalDateTime(final Calendar cal, final int timeFormat) {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, transTimeFormat(timeFormat), iLocale);
df.setCalendar(cal);
return df.format(cal.getTime());
}
示例3: formatCalDateOnly
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalDateOnly(final Calendar cal) {
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, iLocale);
df.setCalendar(cal);
return df.format(cal.getTime());
}
示例4: formatCalTimeOnly
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalTimeOnly(final Calendar cal, final int timeFormat) {
DateFormat df = DateFormat.getTimeInstance(transTimeFormat(timeFormat), iLocale);
df.setCalendar(cal);
return df.format(cal.getTime());
}