本文整理汇总了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());
}
示例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));
}
}
}
示例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);
}
示例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!");
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
}
示例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();
}
}
示例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;
}
});
}
示例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());
}
示例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));
}
示例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());
}