本文整理汇总了Java中javax.xml.datatype.Duration.getDays方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.getDays方法的具体用法?Java Duration.getDays怎么用?Java Duration.getDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.datatype.Duration
的用法示例。
在下文中一共展示了Duration.getDays方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNewDurationDayTimeLexicalRepresentation
import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public void testNewDurationDayTimeLexicalRepresentation() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime("P1DT23H59M65S");
int days = d.getDays();
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例2: testNewDurationDayTimeMilliseconds
import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public void testNewDurationDayTimeMilliseconds() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime(172805000L);
int days = d.getDays();
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例3: testNewDurationDayTimeBigInteger
import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public void testNewDurationDayTimeBigInteger() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
BigInteger day = new BigInteger("1");
BigInteger hour = new BigInteger("23");
BigInteger min = new BigInteger("59");
BigInteger sec = new BigInteger("65");
Duration d = dtf.newDurationDayTime(true, day, hour, min, sec);
int days = d.getDays();
System.out.println("Days: " + days);
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例4: testNewDurationDayTimeInt
import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public void testNewDurationDayTimeInt() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime(true, 1, 23, 59, 65);
int days = d.getDays();
System.out.println("Days: " + days);
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例5: add
import javax.xml.datatype.Duration; //导入方法依赖的package包/类
/**
* 计算结束时间.
*/
public Date add(Date startDate, Duration duration) {
// 得到对应的时间
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
// 添加年数和月数,工作日方面年和月的概念不会改变
calendar.add(Calendar.YEAR, duration.getYears());
calendar.add(Calendar.MONTH, duration.getMonths());
// 天数,小时,分钟可能因为工作日有概念,所以特殊处理
int day = duration.getDays();
int hour = duration.getHours();
int minute = duration.getMinutes();
if (accurateToDay) {
// 有时需要自动把一天换算成8个小时,以实际计算工时
hour += (day * HOUR_OF_DAY);
day = 0;
} else {
Date workDate = this.findWorkDate(calendar.getTime());
calendar.setTime(workDate);
// 目前还没有更好的算法,所以对天数累加,再判断是否工作日
for (int i = 0; i < day; i++) {
calendar.add(Calendar.DATE, 1);
int originHour = calendar.get(Calendar.HOUR_OF_DAY);
int originMinute = calendar.get(Calendar.MINUTE);
// 如果当前就是工作日,就返回当前时间
// 如果当前的时间已经不是工作日了就返回最近的工作日
workDate = this.findWorkDate(calendar.getTime());
calendar.setTime(workDate);
calendar.set(Calendar.HOUR_OF_DAY, originHour);
calendar.set(Calendar.MINUTE, originMinute);
}
}
Date targetDate = calendar.getTime();
long millis = (hour * MILLIS_OF_HOUR) + (minute * MILLIS_OF_MINUTE);
DayPart dayPart = this.findDayPart(targetDate);
boolean isInbusinessHours = (dayPart != null);
if (!isInbusinessHours) {
DayPartResult dayPartResult = this.findTargetWorkDay(targetDate)
.findNextDayPartStart(0, targetDate);
targetDate = dayPartResult.getDate();
dayPart = dayPartResult.getDayPart();
}
Date end = dayPart.add(targetDate, millis);
return end;
}