本文整理汇总了Java中com.ibm.icu.util.Calendar.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.getInstance方法的具体用法?Java Calendar.getInstance怎么用?Java Calendar.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMonthAndYearString
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private static String getMonthAndYearString(MonthAdapter.CalendarDay day) {
Calendar cal = Calendar.getInstance(new ULocale("fa_IR"));
cal.set(day.year, day.month, day.day);
String pattern = DateTimePatternGenerator.getInstance(new ULocale("fa_IR")).getBestPattern("MMMM");
com.ibm.icu.text.SimpleDateFormat formatter = new com.ibm.icu.text.SimpleDateFormat(pattern, new ULocale("fa_IR"));
String sbuf = "";
sbuf += formatter.format(cal);
sbuf += " ";
sbuf += YEAR_FORMAT.format(cal.getTime());
Log.d("sbuf", sbuf);
return sbuf;
}
示例2: capacityRemainingBackward
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Used to request the remaining capacity available for dateFrom in a TechDataCalenda,
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is zero.
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return long capacityRemaining
*/
public static long capacityRemainingBackward(GenericValue techDataCalendar, Timestamp dateFrom) {
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage exception week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module);
return 0;
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
int moveDay = ((Integer) position.get("moveDay")).intValue();
if (moveDay != 0) return 0;
Time startTime = (Time) position.get("startTime");
Double capacity = (Double) position.get("capacity");
Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateFrom).getTime() + startTime.getTime() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateFrom.before(startAvailablePeriod)) return 0;
Timestamp endAvailablePeriod = new Timestamp(startAvailablePeriod.getTime()+capacity.longValue());
if (dateFrom.after(endAvailablePeriod)) return 0;
return dateFrom.getTime() - startAvailablePeriod.getTime();
}
示例3: 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();
}
示例4: get
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Creates a DateFormat with the given time and/or date style in the given
* locale.
* @param dateStyle a value from 0 to 3 indicating the time format,
* or -1 to indicate no date
* @param timeStyle a value from 0 to 3 indicating the time format,
* or -1 to indicate no time
* @param loc the locale for the format
* @param cal the calendar to be used, or null
*/
private static DateFormat get(int dateStyle, int timeStyle, ULocale loc, Calendar cal) {
if((timeStyle != DateFormat.NONE && (timeStyle & RELATIVE)>0) ||
(dateStyle != DateFormat.NONE && (dateStyle & RELATIVE)>0)) {
RelativeDateFormat r = new RelativeDateFormat(timeStyle, dateStyle /* offset? */, loc, cal);
return r;
}
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);
}
if (cal == null) {
cal = Calendar.getInstance(loc);
}
try {
DateFormat result = cal.getDateTimeFormat(dateStyle, timeStyle, loc);
result.setLocale(cal.getLocale(ULocale.VALID_LOCALE),
cal.getLocale(ULocale.ACTUAL_LOCALE));
return result;
} catch (MissingResourceException e) {
///CLOVER:OFF
// coverage requires separate run with no data, so skip
return new SimpleDateFormat("M/d/yy h:mm a");
///CLOVER:ON
}
}
示例5: initialize
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private void initialize() {
if (locale == null) {
locale = ULocale.getDefault(Category.FORMAT);
}
if (formatData == null) {
formatData = new DateFormatSymbols(locale);
}
if (calendar == null) {
calendar = Calendar.getInstance(locale);
}
if (numberFormat == null) {
NumberingSystem ns = NumberingSystem.getInstance(locale);
if (ns.isAlgorithmic()) {
numberFormat = NumberFormat.getInstance(locale);
} else {
String digitString = ns.getDescription();
String nsName = ns.getName();
// Use a NumberFormat optimized for date formatting
numberFormat = new DateNumberFormat(locale, digitString, nsName);
}
}
// Note: deferring calendar calculation until when we really need it.
// Instead, we just record time of construction for backward compatibility.
defaultCenturyBase = System.currentTimeMillis();
setLocale(calendar.getLocale(ULocale.VALID_LOCALE ), calendar.getLocale(ULocale.ACTUAL_LOCALE));
initLocalZeroPaddingNumberFormat();
if (override != null) {
initNumberFormatters(locale);
}
parsePattern();
}
示例6: getDefaultPattern
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private static synchronized String getDefaultPattern() {
ULocale defaultLocale = ULocale.getDefault(Category.FORMAT);
if (!defaultLocale.equals(cachedDefaultLocale)) {
cachedDefaultLocale = defaultLocale;
Calendar cal = Calendar.getInstance(cachedDefaultLocale);
try {
// Load the calendar data directly.
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(
ICUData.ICU_BASE_NAME, cachedDefaultLocale);
String resourcePath = "calendar/" + cal.getType() + "/DateTimePatterns";
ICUResourceBundle patternsRb= rb.findWithFallback(resourcePath);
if (patternsRb == null) {
patternsRb = rb.findWithFallback("calendar/gregorian/DateTimePatterns");
}
if (patternsRb == null || patternsRb.getSize() < 9) {
cachedDefaultPattern = FALLBACKPATTERN;
} else {
int defaultIndex = 8;
if (patternsRb.getSize() >= 13) {
defaultIndex += (SHORT + 1);
}
String basePattern = patternsRb.getString(defaultIndex);
cachedDefaultPattern = SimpleFormatterImpl.formatRawPattern(
basePattern, 2, 2,
patternsRb.getString(SHORT), patternsRb.getString(SHORT + 4));
}
} catch (MissingResourceException e) {
cachedDefaultPattern = FALLBACKPATTERN;
}
}
return cachedDefaultPattern;
}
示例7: initializeCalendar
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* initializes fCalendar from parameters. Returns fCalendar as a convenience.
* @param zone Zone to be adopted, or NULL for TimeZone::createDefault().
* @param locale Locale of the calendar
* @param status Error code
* @return the newly constructed fCalendar
*/
private Calendar initializeCalendar(TimeZone zone, ULocale locale) {
if (calendar == null) {
if(zone == null) {
calendar = Calendar.getInstance(locale);
} else {
calendar = Calendar.getInstance(zone, locale);
}
}
return calendar;
}
示例8: cleanSyncRemoveInfo
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Clean EntitySyncRemove Info
*@param dctx The DispatchContext that this service is operating in
*@param context Map containing the input parameters
*@return Map with the result of the service, the output parameters
*/
public static Map<String, Object> cleanSyncRemoveInfo(DispatchContext dctx, Map<String, ? extends Object> context) {
Debug.logInfo("Running cleanSyncRemoveInfo", module);
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale) context.get("locale");
try {
// find the largest keepRemoveInfoHours value on an EntitySyncRemove and kill everything before that, if none found default to 10 days (240 hours)
double keepRemoveInfoHours = 24;
List<GenericValue> entitySyncRemoveList = EntityQuery.use(delegator).from("EntitySync").queryList();
for (GenericValue entitySyncRemove: entitySyncRemoveList) {
Double curKrih = entitySyncRemove.getDouble("keepRemoveInfoHours");
if (curKrih != null) {
double curKrihVal = curKrih.doubleValue();
if (curKrihVal > keepRemoveInfoHours) {
keepRemoveInfoHours = curKrihVal;
}
}
}
int keepSeconds = (int) Math.floor(keepRemoveInfoHours * 3600);
Calendar nowCal = Calendar.getInstance();
nowCal.setTimeInMillis(System.currentTimeMillis());
nowCal.add(Calendar.SECOND, -keepSeconds);
Timestamp keepAfterStamp = new Timestamp(nowCal.getTimeInMillis());
int numRemoved = delegator.removeByCondition("EntitySyncRemove", EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.LESS_THAN, keepAfterStamp));
Debug.logInfo("In cleanSyncRemoveInfo removed [" + numRemoved + "] values with TX timestamp before [" + keepAfterStamp + "]", module);
return ServiceUtil.returnSuccess();
} catch (GenericEntityException e) {
Debug.logError(e, "Error cleaning out EntitySyncRemove info: " + e.toString(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityExtErrorCleaningEntitySyncRemove", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
示例9: getTimeStampFromIntervalScope
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getTimeStampFromIntervalScope(String iScope, int iCount, Timestamp thruDate) {
iCount--;
if (iCount < 0)
iCount = getIntervalDefaultCount(iScope);
Calendar calendar = (thruDate != null) ? toCalendar(thruDate) : Calendar.getInstance();
if (iScope.equals("hour")) {
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - iCount);
} else if (iScope.equals("day")) {
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - iCount);
} else if (iScope.equals("week")) {
calendar.set(Calendar.DAY_OF_WEEK, 1);
calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR) - iCount);
} else if (iScope.equals("month")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - iCount);
} else if (iScope.equals("quarter")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - (iCount * 3));
} else if (iScope.equals("semester")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - (iCount * 6));
} else if (iScope.equals("year")) {
calendar.set(Calendar.DAY_OF_YEAR, 1);
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - iCount);
}
return UtilDateTime.toTimestamp(calendar.getTime());
}
示例10: getShortDayNamesString
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static String getShortDayNamesString(int[] daysOfWeek) {
String dayNames = null;
Format formatter = new SimpleDateFormat(TWO_CHARACTER_SHORT_DAY_PATTERN, Locale.getDefault());
Calendar calendar = Calendar.getInstance();
for(int day = 0; day < daysOfWeek.length; day++) {
calendar.set(Calendar.DAY_OF_WEEK, daysOfWeek[day]);
if (day == 0) {
dayNames = formatter.format(calendar.getTime()).toUpperCase(Locale.getDefault());
} else {
dayNames += " " + formatter.format(calendar.getTime()).toUpperCase(Locale.getDefault());
}
}
return dayNames;
}
示例11: getStartDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public Calendar getStartDate() {
if (selectableDays != null) return selectableDays[0];
if (mMinDate != null) return mMinDate;
Calendar output = Calendar.getInstance();
output.set(Calendar.YEAR, mMinYear);
output.set(Calendar.DAY_OF_MONTH, 1);
output.set(Calendar.MONTH, Calendar.JANUARY);
return output;
}
示例12: getMinuteRangeAsSet
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public Set<Integer> getMinuteRangeAsSet() {
Set<Integer> rangeSet = new TreeSet<Integer>();
if (this.start == this.end) {
rangeSet.add(this.start);
} else {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, this.start);
while (cal.get(Calendar.HOUR_OF_DAY) != this.end) {
rangeSet.add(cal.get(Calendar.HOUR_OF_DAY));
cal.add(Calendar.HOUR_OF_DAY, 1);
}
}
return rangeSet;
}
示例13: getDayNames
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Returns a List of day name Strings - suitable for calendar headings.
* @param locale
* @return List of day name Strings
*/
public static List<String> getDayNames(Locale locale) {
Calendar tempCal = Calendar.getInstance(locale);
tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE", locale);
List<String> resultList = new ArrayList<String>();
for (int i = 0; i < 7; i++) {
resultList.add(dateFormat.format(tempCal.getTime()));
tempCal.roll(Calendar.DAY_OF_WEEK, 1);
}
return resultList;
}
示例14: startNextDay
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Used to move in a TechDataCalenda, produce the Timestamp for the begining of the next day available and its associated capacity.
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is the next day available
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return a map with Timestamp dateTo, Double nextCapacity
*/
public static Map<String, Object> startNextDay(GenericValue techDataCalendar, Timestamp dateFrom) {
Map<String, Object> result = FastMap.newInstance();
Timestamp dateTo = null;
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage execption week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module);
return ServiceUtil.returnError("Pb reading Calendar Week associated with calendar");
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
Time startTime = (Time) position.get("startTime");
int moveDay = ((Integer) position.get("moveDay")).intValue();
dateTo = (moveDay == 0) ? dateFrom : UtilDateTime.getDayStart(dateFrom,moveDay);
Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateTo).getTime() + startTime.getTime() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateTo.before(startAvailablePeriod)) {
dateTo = startAvailablePeriod;
}
else {
dateTo = UtilDateTime.getNextDayStart(dateTo);
cDateTrav.setTime(dateTo);
position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
startTime = (Time) position.get("startTime");
moveDay = ((Integer) position.get("moveDay")).intValue();
if (moveDay != 0) dateTo = UtilDateTime.getDayStart(dateTo,moveDay);
dateTo.setTime(dateTo.getTime() + startTime.getTime() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
}
result.put("dateTo",dateTo);
result.put("nextCapacity",position.get("capacity"));
return result;
}
示例15: endPreviousDay
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Used to move in a TechDataCalenda, produce the Timestamp for the end of the previous day available and its associated capacity.
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is the previous day available
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return a map with Timestamp dateTo, Double previousCapacity
*/
public static Map<String, Object> endPreviousDay(GenericValue techDataCalendar, Timestamp dateFrom) {
Map<String, Object> result = FastMap.newInstance();
Timestamp dateTo = null;
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage exception week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module);
return ServiceUtil.returnError("Pb reading Calendar Week associated with calendar");
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
Time startTime = (Time) position.get("startTime");
int moveDay = ((Integer) position.get("moveDay")).intValue();
Double capacity = (Double) position.get("capacity");
dateTo = (moveDay == 0) ? dateFrom : UtilDateTime.getDayEnd(dateFrom, Long.valueOf(moveDay));
Timestamp endAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateTo).getTime() + startTime.getTime() + capacity.longValue() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateTo.after(endAvailablePeriod)) {
dateTo = endAvailablePeriod;
}
else {
dateTo = UtilDateTime.getDayStart(dateTo, -1);
cDateTrav.setTime(dateTo);
position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
startTime = (Time) position.get("startTime");
moveDay = ((Integer) position.get("moveDay")).intValue();
capacity = (Double) position.get("capacity");
if (moveDay != 0) dateTo = UtilDateTime.getDayStart(dateTo,moveDay);
dateTo.setTime(dateTo.getTime() + startTime.getTime() + capacity.longValue() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
}
result.put("dateTo",dateTo);
result.put("previousCapacity",position.get("capacity"));
return result;
}