本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.toCalendar方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.toCalendar方法的具體用法?Java DateUtils.toCalendar怎麽用?Java DateUtils.toCalendar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateUtils
的用法示例。
在下文中一共展示了DateUtils.toCalendar方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateHits
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 更新點擊數
*/
@SuppressWarnings("unchecked")
private void updateHits() {
Ehcache cache = cacheManager.getEhcache(Product.HITS_CACHE_NAME);
List<Long> ids = cache.getKeys();
for (Long id : ids) {
Product product = productDao.find(id);
if (product != null) {
productDao.lock(product, LockModeType.PESSIMISTIC_WRITE);
Element element = cache.get(id);
long hits = (Long) element.getObjectValue();
long increment = hits - product.getHits();
Calendar nowCalendar = Calendar.getInstance();
Calendar weekHitsCalendar = DateUtils.toCalendar(product.getWeekHitsDate());
Calendar monthHitsCalendar = DateUtils.toCalendar(product.getMonthHitsDate());
if (nowCalendar.get(Calendar.YEAR) != weekHitsCalendar.get(Calendar.YEAR) || nowCalendar.get(Calendar.WEEK_OF_YEAR) > weekHitsCalendar.get(Calendar.WEEK_OF_YEAR)) {
product.setWeekHits(increment);
} else {
product.setWeekHits(product.getWeekHits() + increment);
}
if (nowCalendar.get(Calendar.YEAR) != monthHitsCalendar.get(Calendar.YEAR) || nowCalendar.get(Calendar.MONTH) > monthHitsCalendar.get(Calendar.MONTH)) {
product.setMonthHits(increment);
} else {
product.setMonthHits(product.getMonthHits() + increment);
}
product.setHits(hits);
product.setWeekHitsDate(new Date());
product.setMonthHitsDate(new Date());
productDao.merge(product);
}
}
}
示例2: getEnd
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Date getEnd() {
HoursAndMinutes hoursAndMinutes = HoursAndMinutes.fromTimeEntry(timeEntry);
Calendar dateCal = DateUtils.toCalendar(getStart());
dateCal.set(Calendar.HOUR_OF_DAY, hoursAndMinutes.getHours());
dateCal.set(Calendar.MINUTE, hoursAndMinutes.getMinutes());
return dateCal.getTime();
}