当前位置: 首页>>代码示例>>Java>>正文


Java Calendar类代码示例

本文整理汇总了Java中com.ibm.icu.util.Calendar的典型用法代码示例。如果您正苦于以下问题:Java Calendar类的具体用法?Java Calendar怎么用?Java Calendar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Calendar类属于com.ibm.icu.util包,在下文中一共展示了Calendar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCalendarTypeToUse

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
private String getCalendarTypeToUse(ULocale uLocale) {
    // Get the correct calendar type
    // TODO: C++ and Java are inconsistent (see #9952).
    String calendarTypeToUse = uLocale.getKeywordValue("calendar");
    if ( calendarTypeToUse == null ) {
        String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", uLocale, true);
        calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
    }
    if ( calendarTypeToUse == null ) {
        calendarTypeToUse = "gregorian"; // fallback
    }
    return calendarTypeToUse;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:14,代码来源:DateTimePatternGenerator.java

示例2: subFormat

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * Formats a single field. This is the version called internally; it
 * adds fieldNum and capitalizationContext parameters.
 *
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
protected String subFormat(char ch, int count, int beginOffset,
                           int fieldNum, DisplayContext capitalizationContext,
                           FieldPosition pos,
                           Calendar cal)
{
    StringBuffer buf = new StringBuffer();
    subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);
    return buf.toString();
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:SimpleDateFormat.java

示例3: subFormat

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Override
@Deprecated
protected void subFormat(StringBuffer buf,
                         char ch, int count, int beginOffset,
                         int fieldNum, DisplayContext capitalizationContext,
                         FieldPosition pos,
                         Calendar cal) {

    // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat,
    // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we
    // just use its implementation
    super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);

    // The following is no longer an issue for this subclass...
    // TODO: add code to set FieldPosition for 'G' and 'l' fields. This
    // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
    // code that handles this at the end of SimpleDateFormat.subFormat.
    // The logic should be moved up into SimpleDateFormat.format.
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:25,代码来源:ChineseDateFormat.java

示例4: format

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * Formats a relative date without a quantity.
 * @param direction NEXT, LAST, THIS, etc.
 * @param unit e.g SATURDAY, DAY, MONTH
 * @return the formatted string. If direction has a value that is documented as not being
 *  fully supported in every locale (for example NEXT_2 or LAST_2) then this function may
 *  return null to signal that no formatted string is available.
 * @throws IllegalArgumentException if the direction is incompatible with
 * unit this can occur with NOW which can only take PLAIN.
 * @stable ICU 53
 */
public String format(Direction direction, AbsoluteUnit unit) {
    if (unit == AbsoluteUnit.NOW && direction != Direction.PLAIN) {
        throw new IllegalArgumentException("NOW can only accept direction PLAIN.");
    }
    String result;
    // Get plain day of week names from DateFormatSymbols.
    if ((direction == Direction.PLAIN) &&  (AbsoluteUnit.SUNDAY.ordinal() <= unit.ordinal() &&
            unit.ordinal() <= AbsoluteUnit.SATURDAY.ordinal())) {
        // Convert from AbsoluteUnit days to Calendar class indexing.
        int dateSymbolsDayOrdinal = (unit.ordinal() - AbsoluteUnit.SUNDAY.ordinal()) + Calendar.SUNDAY;
        String[] dayNames =
                dateFormatSymbols.getWeekdays(DateFormatSymbols.STANDALONE,
                styleToDateFormatSymbolsWidth[style.ordinal()]);
        result = dayNames[dateSymbolsDayOrdinal];
    } else {
        // Not PLAIN, or not a weekday.
        result = getAbsoluteUnitString(style, unit, direction);
    }
    return result != null ? adjustForContext(result) : null;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:32,代码来源:RelativeDateTimeFormatter.java

示例5: validateAndProcessPatternLetter

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * Processes the pattern letter
 * @param patternLetter
 * @return Pattern letter
 */
private CharSequence validateAndProcessPatternLetter(CharSequence patternLetter) {
    // Check that patternLetter is just one letter
    if (patternLetter.length() != 1) { return null; }

    // Check that the pattern letter is accepted
    char letter = patternLetter.charAt(0);
    if (ACCEPTED_PATTERN_LETTERS.indexOf(letter) < 0) {
        return null;
    }

    // Replace 'h' for 'H'
    if (letter == CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.HOUR_OF_DAY].charAt(0)) {
        patternLetter = CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.HOUR];
    }

    return patternLetter;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:23,代码来源:DateIntervalInfo.java

示例6: DateFormatSymbols

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * Variant of DateFormatSymbols(Calendar, ULocale) that takes the Calendar class
 * instead of a Calendar instance.
 * @see #DateFormatSymbols(Calendar, Locale)
 * @stable ICU 3.2
 */
public DateFormatSymbols(Class<? extends Calendar> calendarClass, ULocale locale) {
    String fullName = calendarClass.getName();
    int lastDot = fullName.lastIndexOf('.');
    String className = fullName.substring(lastDot+1);
    String calType = null;
    for (String[] calClassInfo : CALENDAR_CLASSES) {
        if (calClassInfo[0].equals(className)) {
            calType = calClassInfo[1];
            break;
        }
    }
    if (calType == null) {
        calType = className.replaceAll("Calendar", "").toLowerCase(Locale.ENGLISH);
    }

    initializeData(locale, calType);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:24,代码来源:DateFormatSymbols.java

示例7: format

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * Formats a date or time, which is the standard millis
 * since January 1, 1970, 00:00:00 GMT.
 * <p>Example: using the US locale:
 * "yyyy.MM.dd G 'at' HH:mm:ss zzz" -&gt;&gt; 1996.07.10 AD at 15:08:56 PDT
 * @param cal the calendar whose date-time value is to be formatted into a date-time string
 * @param toAppendTo where the new date-time text is to be appended
 * @param pos the formatting position. On input: an alignment field,
 * if desired. On output: the offsets of the alignment field.
 * @return the formatted date-time string.
 * @see DateFormat
 * @stable ICU 2.0
 */
@Override
public StringBuffer format(Calendar cal, StringBuffer toAppendTo,
                           FieldPosition pos) {
    TimeZone backupTZ = null;
    if (cal != calendar && !cal.getType().equals(calendar.getType())) {
        // Different calendar type
        // We use the time and time zone from the input calendar, but
        // do not use the input calendar for field calculation.
        calendar.setTimeInMillis(cal.getTimeInMillis());
        backupTZ = calendar.getTimeZone();
        calendar.setTimeZone(cal.getTimeZone());
        cal = calendar;
    }
    StringBuffer result = format(cal, getContext(DisplayContext.Type.CAPITALIZATION), toAppendTo, pos, null);
    if (backupTZ != null) {
        // Restore the original time zone
        calendar.setTimeZone(backupTZ);
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:34,代码来源:SimpleDateFormat.java

示例8: dayDifference

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * @return the number of days in "until-now"
 */
private static int dayDifference(Calendar until) {
    Calendar nowCal = (Calendar)until.clone();
    Date nowDate = new Date(System.currentTimeMillis());
    nowCal.clear();
    nowCal.setTime(nowDate);
    int dayDiff = until.get(Calendar.JULIAN_DAY) - nowCal.get(Calendar.JULIAN_DAY);
    return dayDiff;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:12,代码来源:RelativeDateFormat.java

示例9: getCalendarTypeString

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * This method returns the calendar type as string.
 *
 * @param calendar
 *            the Calendar date
 * @return The clendar type as string. If Calendar is empty an empty string will be returned.
 */
public static String getCalendarTypeString(Calendar calendar) {
    if (calendar == null) {
        return "";
    }
    if (calendar instanceof IslamicCalendar) {
        return TAG_ISLAMIC;
    } else if (calendar instanceof CopticCalendar) {
        return TAG_COPTIC;
    } else if (calendar instanceof EthiopicCalendar) {
        return TAG_ETHIOPIC;
    } else if (calendar instanceof GregorianCalendar) {
        return TAG_GREGORIAN;
    } else {
        return TAG_JULIAN;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRCalendar.java

示例10: testDateFormatsWithoutTimezone

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
@Test
public void testDateFormatsWithoutTimezone() {
    // Christmas :-) 
    int year = 2015, month = 12, day = 25;

    GregorianCalendar gIn = new GregorianCalendar(year, month - 1, day);
    Element element = new Element("date");
    MCRMODSDateHelper.setDate(element, gIn, MCRMODSDateFormat.w3cdtf_10);

    // Not christmas :-( ?
    assertEquals(year + "-" + month + "-" + day, element.getText());

    // Not christmas :-( ?
    GregorianCalendar gOut = MCRMODSDateHelper.getCalendar(element);
    assertEquals(day, gOut.get(Calendar.DAY_OF_MONTH));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:17,代码来源:MCRMODSDateHelperTest.java

示例11: includesDate

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
@Override
public boolean includesDate(Calendar cal) {
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour == this.start || hour == this.end) {
        return true;
    }
    Calendar compareCal = (Calendar) cal.clone();
    compareCal.set(Calendar.HOUR_OF_DAY, this.start);
    while (compareCal.get(Calendar.HOUR_OF_DAY) != this.end) {
        if (compareCal.get(Calendar.HOUR_OF_DAY) == hour) {
            return true;
        }
        compareCal.add(Calendar.HOUR_OF_DAY, 1);
    }
    return false;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:TemporalExpressions.java

示例12: Frequency

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * @param start Starting date, defaults to current system time
 * @param freqType One of the following integer values: <code>Calendar.SECOND
 * Calendar.MINUTE Calendar.HOUR Calendar.DAY_OF_MONTH Calendar.MONTH
 * Calendar.YEAR</code>
 * @param freqCount A positive integer
 */
public Frequency(Date start, int freqType, int freqCount) {
    if (freqType != Calendar.SECOND && freqType != Calendar.MINUTE
            && freqType != Calendar.HOUR && freqType != Calendar.DAY_OF_MONTH
            && freqType != Calendar.MONTH && freqType != Calendar.YEAR) {
        throw new IllegalArgumentException("Invalid freqType argument");
    }
    if (freqCount < 1) {
        throw new IllegalArgumentException("freqCount argument must be a positive integer");
    }
    if (start != null) {
        this.start = start;
    } else {
        this.start = new Date();
    }
    this.sequence = SEQUENCE_FREQ + freqType;
    this.freqType = freqType;
    this.freqCount = freqCount;
    if (Debug.verboseOn()) {
        Debug.logVerbose("Created " + this, module);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:29,代码来源:TemporalExpressions.java

示例13: getEvenStartingTime

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
private static long getEvenStartingTime(long binLength) {
    // binLengths should be a divisable evenly into 1 hour
    long curTime = System.currentTimeMillis();

    // find the first previous millis that are even on the hour
    Calendar cal = Calendar.getInstance();

    cal.setTime(new Date(curTime));
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    while (cal.getTime().getTime() < (curTime - binLength)) {
        cal.add(Calendar.MILLISECOND, (int) binLength);
    }

    return cal.getTime().getTime();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:19,代码来源:ServerHitBin.java

示例14: visit

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void visit(TemporalExpressions.DayOfWeekRange expr) {
    int startDay = expr.getStartDay();
    int endDay = expr.getEndDay();
    WeekDayList dayList = new WeekDayList();
    dayList.add(dayOfWeekArray[startDay - 1]);
    while (startDay != endDay) {
        startDay++;
        if (startDay > Calendar.SATURDAY) {
            startDay = Calendar.SUNDAY;
        }
        dayList.add(dayOfWeekArray[startDay - 1]);
    }
    Recur recur = new Recur(Recur.DAILY, 0);
    recur.getDayList().addAll(dayList);
    this.state.addRecur(recur);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:19,代码来源:ICalRecurConverter.java

示例15: getCommonSemesterDateFormat

import com.ibm.icu.util.Calendar; //导入依赖的package包/类
/**
 * SCIPIO: Returns a DateFormat for semester.
 * FIXME: currently only supports format, not parse!
 */
@SuppressWarnings("serial")
public static DateFormat getCommonSemesterDateFormat(final Locale locale, final TimeZone timezone) {
    return new DateFormat() {
        @Override
        public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
            int month = toCalendar(date, timezone, locale).get(Calendar.MONTH);
            int semester = (int) (month / 6); // zero-based
            toAppendTo.append(new SimpleDateFormat("yyyy-'" + (semester + 1) + "S'").format(date));
            return toAppendTo;
        }
        @Override
        public Date parse(String source, ParsePosition pos) {
            throw new UnsupportedOperationException();
        }
    };
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:21,代码来源:UtilDateTime.java


注:本文中的com.ibm.icu.util.Calendar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。