本文整理汇总了Java中com.ibm.icu.util.Calendar.setTime方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.setTime方法的具体用法?Java Calendar.setTime怎么用?Java Calendar.setTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.setTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: capacityRemaining
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Used to to request the remain 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 capacityRemaining(GenericValue techDataCalendar, Timestamp dateFrom) {
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 0;
}
// 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));
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 endAvailablePeriod.getTime() - dateFrom.getTime();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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;
}
示例6: 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;
}
示例7: convert
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public java.sql.Date convert(java.util.Date obj) throws ConversionException {
Calendar cal = Calendar.getInstance();
cal.setTime(obj);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
return new java.sql.Date(cal.getTimeInMillis());
}
示例8: toDateString
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Makes a date String in the given from a Date
*
* @param date The Date
* @return A date String in the given format
*/
public static String toDateString(java.util.Date date, String format) {
if (date == null) return "";
SimpleDateFormat dateFormat = null;
if (format != null) {
dateFormat = new SimpleDateFormat(format);
} else {
dateFormat = new SimpleDateFormat();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return dateFormat.format(date);
}
示例9: toTimeString
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Makes a time String in the format HH:MM:SS from a Date. If the seconds are 0, then the output is in HH:MM.
*
* @param date The Date
* @return A time String in the format HH:MM:SS or HH:MM
*/
public static String toTimeString(java.util.Date date) {
if (date == null) return "";
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return (toTimeString(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)));
}
示例10: weekNumber
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static int weekNumber(Timestamp input, int startOfWeek) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(startOfWeek);
if (startOfWeek == Calendar.MONDAY) {
calendar.setMinimalDaysInFirstWeek(4);
} else if (startOfWeek == Calendar.SUNDAY) {
calendar.setMinimalDaysInFirstWeek(3);
}
calendar.setTime(new java.util.Date(input.getTime()));
return calendar.get(Calendar.WEEK_OF_YEAR);
}
示例11: prepareCal
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
protected Calendar prepareCal(Calendar cal) {
// Performs a "sane" skip forward in time - avoids time consuming loops
// like incrementing every second from Jan 1 2000 until today
Calendar skip = (Calendar) cal.clone();
skip.setTime(this.start);
long deltaMillis = cal.getTimeInMillis() - this.start.getTime();
if (deltaMillis < 1000) {
return skip;
}
long divisor = deltaMillis;
if (this.freqType == Calendar.DAY_OF_MONTH) {
divisor = 86400000;
} else if (this.freqType == Calendar.HOUR) {
divisor = 3600000;
} else if (this.freqType == Calendar.MINUTE) {
divisor = 60000;
} else if (this.freqType == Calendar.SECOND) {
divisor = 1000;
} else {
return skip;
}
long units = deltaMillis / divisor;
units -= units % this.freqCount;
skip.add(this.freqType, (int)units);
while (skip.after(cal)) {
skip.add(this.freqType, -this.freqCount);
}
return skip;
}
示例12: formatDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Returns a String from a Date object */
public static String formatDate(Date date) {
String formatString = "";
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (cal.isSet(Calendar.MINUTE))
formatString = "yyyyMMdd'T'hhmmss";
else
formatString = "yyyyMMdd";
SimpleDateFormat formatter = new SimpleDateFormat(formatString);
return formatter.format(date);
}
示例13: testGetDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Test getDate.
*
* @throws ParseException
* Signals that an parse exception in application has occurred..
* @throws UNISoNException
* Signals that an exception in application has occurred..
*/
@Test
public void testGetDate() throws ParseException, UNISoNException {
final String dateExpected = "Wed, 11 May 2016 13:10:00 GMT";
final NewsArticle test = new NewsArticle();
Assert.assertNull(test.getDate());
test.setDate(dateExpected);
final Calendar actual = Calendar.getInstance();
actual.setTime(test.getDate());
Assert.assertEquals(4, actual.get(Calendar.MONTH));
}
示例14: makeParamValueFromComposite
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Given the prefix of a composite parameter, recomposes a single Object from
* the composite according to compositeType. For example, consider the following
* form widget field,
*
* <field name="meetingDate">
* <date-time type="timestamp" input-method="time-dropdown">
* </field>
*
* The result in HTML is three input boxes to input the date, hour and minutes separately.
* The parameter names are named meetingDate_c_date, meetingDate_c_hour, meetingDate_c_minutes.
* Additionally, there will be a field named meetingDate_c_compositeType with a value of "Timestamp".
* where _c_ is the COMPOSITE_DELIMITER. These parameters will then be recomposed into a Timestamp
* object from the composite fields.
*
* @param request
* @param prefix
* @return Composite object from data or null if not supported or a parsing error occurred.
*/
public static Object makeParamValueFromComposite(HttpServletRequest request, String prefix, Locale locale) {
String compositeType = request.getParameter(makeCompositeParam(prefix, "compositeType"));
if (UtilValidate.isEmpty(compositeType)) return null;
// collect the composite fields into a map
Map<String, String> data = new HashMap<String, String>();
for (Enumeration<String> names = UtilGenerics.cast(request.getParameterNames()); names.hasMoreElements();) {
String name = names.nextElement();
if (!name.startsWith(prefix + COMPOSITE_DELIMITER)) continue;
// extract the suffix of the composite name
String suffix = name.substring(name.indexOf(COMPOSITE_DELIMITER) + COMPOSITE_DELIMITER_LENGTH);
// and the value of this parameter
String value = request.getParameter(name);
// key = suffix, value = parameter data
data.put(suffix, value);
}
if (Debug.verboseOn()) { Debug.logVerbose("Creating composite type with parameter data: " + data.toString(), module); }
// handle recomposition of data into the compositeType
if ("Timestamp".equals(compositeType)) {
String date = data.get("date");
String hour = data.get("hour");
String minutes = data.get("minutes");
String ampm = data.get("ampm");
if (date == null || date.length() < 10) return null;
if (UtilValidate.isEmpty(hour)) return null;
if (UtilValidate.isEmpty(minutes)) return null;
boolean isTwelveHour = UtilValidate.isNotEmpty(ampm);
// create the timestamp from the data
try {
int h = Integer.parseInt(hour);
Timestamp timestamp = Timestamp.valueOf(date.substring(0, 10) + " 00:00:00.000");
Calendar cal = Calendar.getInstance(locale);
cal.setTime(timestamp);
if (isTwelveHour) {
boolean isAM = ("AM".equals(ampm) ? true : false);
if (isAM && h == 12) h = 0;
if (!isAM && h < 12) h += 12;
}
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, Integer.parseInt(minutes));
return new Timestamp(cal.getTimeInMillis());
} catch (IllegalArgumentException e) {
Debug.logWarning("User input for composite timestamp was invalid: " + e.getMessage(), module);
return null;
}
}
// we don't support any other compositeTypes (yet)
return null;
}
示例15: getNextFreq
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private Date getNextFreq(long startTime, long fromTime) {
// Build a Calendar object
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(startTime));
long nextStartTime = startTime;
while (nextStartTime < fromTime) {
// if (Debug.verboseOn()) Debug.logVerbose("[RecurrenceInfo.getNextFreq] : Updating time - " + getFrequency(), module);
switch (getFrequency()) {
case SECONDLY:
cal.add(Calendar.SECOND, getIntervalInt());
break;
case MINUTELY:
cal.add(Calendar.MINUTE, getIntervalInt());
break;
case HOURLY:
cal.add(Calendar.HOUR_OF_DAY, getIntervalInt());
break;
case DAILY:
cal.add(Calendar.DAY_OF_MONTH, getIntervalInt());
break;
case WEEKLY:
cal.add(Calendar.WEEK_OF_YEAR, getIntervalInt());
break;
case MONTHLY:
cal.add(Calendar.MONTH, getIntervalInt());
break;
case YEARLY:
cal.add(Calendar.YEAR, getIntervalInt());
break;
default:
return null; // should never happen
}
nextStartTime = cal.getTime().getTime();
}
return new Date(nextStartTime);
}