當前位置: 首頁>>代碼示例>>Java>>正文


Java DateUtils類代碼示例

本文整理匯總了Java中org.apache.commons.lang3.time.DateUtils的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils類的具體用法?Java DateUtils怎麽用?Java DateUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DateUtils類屬於org.apache.commons.lang3.time包,在下文中一共展示了DateUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: moveForward

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
/**
 * Advance the cursor with the given duration.
 * 
 * @param duration
 *            Duration to add to current date. Business hours are considered.
 * @return The new date.
 */
public Date moveForward(final long duration) {
	long remainingDuration = duration;
	while (remainingDuration > 0) {
		this.delta = 0;

		// We need to move the cursors
		if (cursorTime + remainingDuration < DateUtils.MILLIS_PER_DAY) {
			// We need to compute the elapsed ranges and hours within the same day
			computeDelayTodayToTime(cursorTime + remainingDuration);
		} else {
			// Move to the end of this day
			computeDelayTodayToTime(DateUtils.MILLIS_PER_DAY);
		}
		remainingDuration -= delta;
	}

	// Return the new date
	return new Date(cursor.getTime() + getCursorTime());
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:27,代碼來源:ComputationContext.java

示例2: testSetInParameter_mapperForLocalDate

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Test
public void testSetInParameter_mapperForLocalDate() throws ParseException, SQLException {

	LocalDate localDate = LocalDate.of(2002, Month.JANUARY, 1);
	Date date = DateUtils.parseDate("2002-01-01", new String[] { "yyyy-MM-dd" });
	try (SqlAgent agent = config.agent()) {
		SqlContext ctx = agent.contextFrom("test/PARAM_MAPPING1").param("targetDate", localDate);

		try (ResultSet rs = agent.query(ctx)) {
			assertThat("結果が0件です。", rs.next(), is(true));
			assertThat(rs.getDate("TARGET_DATE"), is(new java.sql.Date(date.getTime())));

			assertThat("取得データが多すぎます", rs.next(), is(false));
		}

	}
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:18,代碼來源:ParameterTest.java

示例3: linkOrCreate

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
private void linkOrCreate(final int subscription) {
	// Add Configuration
	final BugTrackerConfiguration configuration = new BugTrackerConfiguration();
	configuration.setSubscription(subscriptionRepository.findOne(subscription));
	configuration.setCalendar(getDefaultCalendar());
	repository.saveAndFlush(configuration);

	// 9h to 18h
	final BusinessHours businessRange1 = new BusinessHours();
	businessRange1.setStart(8 * DateUtils.MILLIS_PER_HOUR);
	businessRange1.setEnd(18 * DateUtils.MILLIS_PER_HOUR);
	businessRange1.setConfiguration(configuration);
	businessHoursRepository.saveAndFlush(businessRange1);

	// Set a new SLA
	final Sla sla = new Sla();
	sla.setConfiguration(configuration);
	sla.setDescription("Closing : Open->Closed");
	sla.setStart("OPEN");
	sla.setStop("CLOSED");
	sla.setName("Closing");
	slaRepository.saveAndFlush(sla);
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:24,代碼來源:BugTrackerResource.java

示例4: getDate

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
public static Date getDate(Cell cell, String format) throws ParseException {
    if (isNullCell(cell)) {
        return null;
    }
    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:// 數字類型
            return getCellDate(cell);
        case Cell.CELL_TYPE_STRING:
            if(StringUtils.isNotEmpty(cell.getStringCellValue())){
                return DateUtils.parseDate(cell.getStringCellValue(), format);
            }else{
                return null;
            }
        default:
            throw new RuntimeException("can not convertWithConstructor cell value to Date!");
    }
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:18,代碼來源:CellConvert.java

示例5: addBusinessHoursOverlapsEnd

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Test
public void addBusinessHoursOverlapsEnd() {
	thrown.expect(ValidationJsonException.class);
	thrown.expect(MatcherUtil.validationMatcher("stop", "Overlap"));

	final BusinessHoursEditionVo vo = new BusinessHoursEditionVo();
	vo.setStart(2 * DateUtils.MILLIS_PER_HOUR);
	vo.setEnd(1 * DateUtils.MILLIS_PER_HOUR);
	vo.setSubscription(subscription);
	em.flush();
	em.clear();
	resource.addBusinessHours(vo);
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:14,代碼來源:BugTrackerResourceTest.java

示例6: getValue

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Override
public Date getValue(final String context) {
	final String data = (String) super.getValue(context);

	try {
		final double date = Double.parseDouble(data.replace(',', '.'));
		final Calendar calendar = new GregorianCalendar(); // using default time-zone
		final int wholeDays = (int) Math.floor(date);
		final int millisecondsInDay = (int) Math.round((date - wholeDays) * DateUtils.MILLIS_PER_DAY);

		// Excel thinks 2/29/1900 is a valid date, which it isn't
		calendar.set(1900, 0, wholeDays - 1, 0, 0, 0);
		calendar.set(Calendar.MILLISECOND, millisecondsInDay);
		calendar.add(Calendar.MILLISECOND, 500);
		calendar.clear(Calendar.MILLISECOND);
		return calendar.getTime();
	} catch (final NumberFormatException e) {
		// Invalid format of String
		throw new IllegalArgumentException("Invalid string '" + data + "' for decimal Excel date", e);
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:22,代碼來源:DecimalDateProcessor.java

示例7: testWellKnownUserYesterday

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
/**
 * Loading with a well known user and connected yesterday.
 */
@Test
public void testWellKnownUserYesterday() {
	SystemUser user = em.find(SystemUser.class, DEFAULT_USER);
	user.setLastConnection(new Date(new Date().getTime() - DateUtils.MILLIS_PER_DAY * 2));
	em.persist(user);
	em.flush();
	em.clear();
	final UserDetails userDetails = userDetailsService.loadUserByUsername(DEFAULT_USER);
	Assert.assertEquals(1, userDetails.getAuthorities().size());
	Assert.assertEquals(SystemRole.DEFAULT_ROLE, userDetails.getAuthorities().iterator().next().getAuthority());
	Assert.assertEquals(DEFAULT_USER, userDetails.getUsername());
	user = em.find(SystemUser.class, DEFAULT_USER);
	Assert.assertNotNull(user.getLastConnection());
	Assert.assertTrue(Math.abs(new Date().getTime() - user.getLastConnection().getTime()) < DateUtils.MILLIS_PER_MINUTE);
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:19,代碼來源:RbacUserDetailsServiceTest.java

示例8: attendFailCauseRegistClose

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Test(expected = HttpClientErrorException.class)
@Transactional
public void attendFailCauseRegistClose() {
	Meeting meeting = meetingService.findById(user1MeetingId).get();
	meeting.setMeetingStatus(Meeting.MeetingStatus.PUBLISHED);
	Date minPlusOpenTime = DateUtils.addMinutes(Date.from(ZonedDateTime.now(ZoneOffset.UTC).toInstant()), -10);
	meeting.setRegistCloseAt(minPlusOpenTime);

	meetingAttendService.attend(meeting, baseDataTestHelper.getUser2());
}
 
開發者ID:spring-sprout,項目名稱:osoon,代碼行數:11,代碼來源:MeetingAttendServiceTest.java

示例9: parse

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
private Date parse(String d) {
        Date date = null;
        try {
            date = DateUtils.parseDate(d.substring(0, 8), "yyyyMMdd");
        } catch (Exception e) {
//            e.printStackTrace();
        }
        return date;
    }
 
開發者ID:jt120,項目名稱:take,代碼行數:10,代碼來源:ParseFenHong.java

示例10: ComputationContext

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
/**
 * initialize the computation context.
 * 
 * @param holidays
 *            the holiday list. Each day must be set to start of the day position.
 * @param businessHours
 *            The business hour ranges. May be empty or must be sorted, and first range must start with 0:00
 *            00.000.
 */
public ComputationContext(final List<Date> holidays, final List<BusinessHours> businessHours) {
	this.holidays = holidays;
	if (businessHours.isEmpty()) {
		// Whole day is a working day
		final BusinessHours businessHour = new BusinessHours();
		businessHour.setStart(0);
		businessHour.setEnd(DateUtils.MILLIS_PER_DAY);
		this.businessHours = Collections.singletonList(businessHour);
	} else {
		this.businessHours = businessHours;
	}
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:22,代碼來源:ComputationContext.java

示例11: moveToNextBusinessDayOfWeek

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
/**
 * Move the date to the next business day of week. No updated delta.
 */
private void moveToNextBusinessDayOfWeek() {
	final int dow = DateUtils.toCalendar(cursor).get(Calendar.DAY_OF_WEEK);
	if (dow == Calendar.SUNDAY || dow == Calendar.SATURDAY) {
		// Sunday/Saturday --> Monday 00:00 00.000
		moveToTomorrow();
	}
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:11,代碼來源:ComputationContext.java

示例12: put

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
public void put(final RequestInfo requestInfo) {
    final AppInfo appInfo = requestInfo.getAppInfo();
    final InterfaceInfo interfaceInfo = requestInfo.getInterfaceInfo();
    Date now = new Date();
    Calendar calendar = DateUtils.toCalendar(now);
    final String minuteIndex = getCurrentMinuteIndex(calendar);
    final String currentDay = getCurrentDay(calendar);

    final long cost = requestInfo.getEndTime() - requestInfo.getStartTime();

    final String interfaceCostKey = KeyRole.INTERFACE_COST.getRedisKey(appInfo, interfaceInfo, currentDay);
    final String interfaceKey = KeyRole.INTERFACE.getRedisKey(appInfo, interfaceInfo, currentDay);
    final String appInterfaceKey = KeyRole.APP_INTERFACE.getRedisKey(appInfo, interfaceInfo, currentDay);
    this.redisConfig.execute(new RedisCallback<Object>() {
        @Override
        public Object call(Jedis jedis) {
            Pipeline pipeline = jedis.pipelined();
            // 隻有成功的,才有必要統計請求延遲
            if (requestInfo.isSuccessed()) {
                pipeline.hincrBy(interfaceCostKey, minuteIndex, cost);
            }
            final String filed = requestInfo.isSuccessed() ? minuteIndex + "s" : minuteIndex + "f";
            pipeline.hincrBy(interfaceKey, filed, 1);
            pipeline.hincrBy(appInterfaceKey, filed, 1);
            pipeline.sync();

            if (requestInfo.isSuccessed()) {
                expire(jedis, interfaceCostKey);
            }
            expire(jedis, interfaceKey);
            expire(jedis, appInterfaceKey);
            return null;
        }
    });

}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:37,代碼來源:StatisticsCacheServiceAbstract.java

示例13: moveForwardMidnightLessOne

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Test
public void moveForwardMidnightLessOne() {
	final ComputationContext context = new ComputationContext(new ArrayList<>(), new ArrayList<>());
	context.reset(getDate(2014, 03, 03));
	final Date end = new Date(getDate(2014, 03, 04).getTime() - 1);
	Assert.assertEquals(DateUtils.MILLIS_PER_DAY - 1, context.moveForward(end));
	Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
	Assert.assertEquals(DateUtils.MILLIS_PER_DAY - 1, context.getCursorTime());
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:10,代碼來源:ComputationContextTest.java

示例14: testGetValue

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
/**
 * Simple date format of static context.
 */
@Test
public void testGetValue() throws ParseException {
	final Deque<Object> contextData = new LinkedList<>();
	final SystemUser systemUser = new SystemUser();
	contextData.add(systemUser);
	final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd", null, null);
	Assert.assertEquals("2014/05/30", new FormatProcessor<>(df, DateUtils.parseDate("2014/05/30", "yyyy/MM/dd")).getValue(contextData));
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:12,代碼來源:FormatProcessorTest.java

示例15: moveForwardPlusOnePartialWeek

import org.apache.commons.lang3.time.DateUtils; //導入依賴的package包/類
@Test
public void moveForwardPlusOnePartialWeek() {
	final ComputationContext context = new ComputationContext(new ArrayList<>(), new ArrayList<>());
	context.reset(getDate(2014, 03, 03));
	Assert.assertEquals(5 * DateUtils.MILLIS_PER_DAY, context.moveForward(getDate(2014, 03, 8)));
	Assert.assertEquals(getDate(2014, 03, 10), context.getCursor());
}
 
開發者ID:ligoj,項目名稱:plugin-bt,代碼行數:8,代碼來源:ComputationContextTest.java


注:本文中的org.apache.commons.lang3.time.DateUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。