欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实操指南:Java 中 ChineseCalendar 类的运用示例

最编程 2024-02-10 18:17:10
...

实例1: LunarCalendar

import com.ibm.icu.util.ChineseCalendar; //导入依赖的package包/类
public LunarCalendar(TimeZone ptimezone, Locale plocale) {
	if(ptimezone==null){
		timezone=TimeZone.getDefault();
	}else{
		timezone=ptimezone;
	}
	if(plocale==null){
		locale=Locale.getDefault();
	}else{
		locale=plocale;
	}
	icu_timezone = com.ibm.icu.util.TimeZone.getTimeZone(timezone.getID());
	
	cal=Calendar.getInstance(timezone, locale);
	ccal=new ChineseCalendar(icu_timezone, locale);
}
 

实例2: GregorianToLunar

import com.ibm.icu.util.ChineseCalendar; //导入依赖的package包/类
public Date GregorianToLunar(Date date){
	cal = Calendar.getInstance(timezone, locale);
	ccal = new ChineseCalendar(icu_timezone, locale);
	
	cal.set(Calendar.YEAR, Integer.parseInt(year_sdf.format(date)));
	cal.set(Calendar.MONTH, Integer.parseInt(month_sdf.format(date))-CALENDAR_MONTH_GAP);
	cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day_sdf.format(date)));
	
	ccal.setTimeInMillis(cal.getTimeInMillis());
	
	cal.set(Calendar.YEAR, ccal.get(ChineseCalendar.EXTENDED_YEAR)-CALENDAR_YEAR_GAP);
	cal.set(Calendar.MONTH, ccal.get(ChineseCalendar.MONTH));
	cal.set(Calendar.DAY_OF_MONTH, ccal.get(ChineseCalendar.DAY_OF_MONTH));
	
	return cal.getTime();
}
 

实例3: LunarToGregorian

import com.ibm.icu.util.ChineseCalendar; //导入依赖的package包/类
public Date LunarToGregorian(Date date){
	cal = Calendar.getInstance(timezone, locale);
	ccal = new ChineseCalendar(icu_timezone, locale);
	
	ccal.set(ChineseCalendar.EXTENDED_YEAR, Integer.parseInt(year_sdf.format(date))+CALENDAR_YEAR_GAP);
	ccal.set(ChineseCalendar.MONTH, Integer.parseInt(month_sdf.format(date))-CALENDAR_MONTH_GAP);
	ccal.set(ChineseCalendar.DAY_OF_MONTH, Integer.parseInt(day_sdf.format(date)));
	
	cal.setTimeInMillis(ccal.getTimeInMillis());
	return cal.getTime();
}
 

实例4: ofCalendarField

import com.ibm.icu.util.ChineseCalendar; //导入依赖的package包/类
/**
 * Returns the <code>Field</code> constant that corresponds to the <code>
 * ChineseCalendar</code> field <code>calendarField</code>.  If there is no
 * corresponding <code>Field</code> is available, null is returned.
 *
 * @param calendarField <code>ChineseCalendar</code> field constant
 * @return <code>Field</code> associated with the <code>calendarField</code>,
 * or null if no associated <code>Field</code> is available.
 * @throws IllegalArgumentException if <code>calendarField</code> is not
 * a valid <code>Calendar</code> field constant.
 *
 * @deprecated ICU 50
 */
@Deprecated
public static DateFormat.Field ofCalendarField(int calendarField) {
    // Should we remove the following, since there is no longer a specific
    // date format field for leap month (since 'l' pattern char is obsolete)?
    if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {
        return IS_LEAP_MONTH;
    }
    return DateFormat.Field.ofCalendarField(calendarField);
}
 

实例5: ChineseDateFormat

import com.ibm.icu.util.ChineseCalendar; //导入依赖的package包/类
/**
 * Construct a ChineseDateFormat from a date format pattern, numbering system override and locale
 * @param pattern the pattern
 * @param override The override string.  A numbering system override string can take one of the following forms:
 *     1). If just a numbering system name is specified, it applies to all numeric fields in the date format pattern.
 *     2). To specify an alternate numbering system on a field by field basis, use the field letters from the pattern
 *         followed by an = sign, followed by the numbering system name.  For example, to specify that just the year
 *         be formatted using Hebrew digits, use the override "y=hebr".  Multiple overrides can be specified in a single
 *         string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using
 *         Thai digits for the month and Devanagari digits for the year.
 * @param locale the locale
 * @deprecated ICU 50
 */
@Deprecated
public ChineseDateFormat(String pattern, String override, ULocale locale) {
   super(pattern, new ChineseDateFormatSymbols(locale),
           new ChineseCalendar(TimeZone.getDefault(), locale), locale, true, override);
}