本文整理匯總了Java中org.joda.time.Years.getYears方法的典型用法代碼示例。如果您正苦於以下問題:Java Years.getYears方法的具體用法?Java Years.getYears怎麽用?Java Years.getYears使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.Years
的用法示例。
在下文中一共展示了Years.getYears方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: exec
import org.joda.time.Years; //導入方法依賴的package包/類
@Override
public Long exec(Tuple input) throws IOException
{
if (input == null || input.size() < 2) {
return null;
}
DateTime startDate = (DateTime) input.get(0);
DateTime endDate = (DateTime) input.get(1);
// Larger value first
Years y = Years.yearsBetween(endDate, startDate);
// joda limitation, only integer range, at the risk of overflow, need to be improved
return (long) y.getYears();
}
示例2: exec
import org.joda.time.Years; //導入方法依賴的package包/類
@Override
public Long exec(Tuple input) throws IOException
{
if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
return null;
}
DateTime startDate = (DateTime) input.get(0);
DateTime endDate = (DateTime) input.get(1);
// Larger value first
Years y = Years.yearsBetween(endDate, startDate);
// joda limitation, only integer range, at the risk of overflow, need to be improved
return (long) y.getYears();
}
示例3: getDeltaSinceEpoch
import org.joda.time.Years; //導入方法依賴的package包/類
public static int getDeltaSinceEpoch(int time, int tempRes) {
int delta = 0;
// Epoch
MutableDateTime epoch = new MutableDateTime();
epoch.setDate(0);
DateTime dt = new DateTime(time*1000, DateTimeZone.UTC);
switch(tempRes) {
case FrameworkUtils.HOUR:
Hours hours = Hours.hoursBetween(epoch, dt);
delta = hours.getHours();
break;
case FrameworkUtils.DAY:
Days days = Days.daysBetween(epoch, dt);
delta = days.getDays();
break;
case FrameworkUtils.WEEK:
Weeks weeks = Weeks.weeksBetween(epoch, dt);
delta = weeks.getWeeks();
break;
case FrameworkUtils.MONTH:
Months months = Months.monthsBetween(epoch, dt);
delta = months.getMonths();
break;
case FrameworkUtils.YEAR:
Years years = Years.yearsBetween(epoch, dt);
delta = years.getYears();
break;
default:
hours = Hours.hoursBetween(epoch, dt);
delta = hours.getHours();
break;
}
return delta;
}
示例4: getLengthOfService
import org.joda.time.Years; //導入方法依賴的package包/類
public int getLengthOfService(Employee employee, LocalDate refDate) throws AxelorException{
try{
Years years = Years.yearsBetween(employee.getSeniorityDate(), refDate == null ? Beans.get(GeneralService.class).getTodayDate() : refDate );
return years.getYears();
}catch (IllegalArgumentException e){
throw new AxelorException(String.format( I18n.get( IExceptionMessage.EMPLOYEE_NO_SENIORITY_DATE ), employee.getName() ), IException.NO_VALUE);
}
}
示例5: getAge
import org.joda.time.Years; //導入方法依賴的package包/類
public int getAge(Employee employee, LocalDate refDate) throws AxelorException{
try{
Years years = Years.yearsBetween(employee.getBirthDate(), refDate == null ? Beans.get(GeneralService.class).getTodayDate() : refDate );
return years.getYears();
}catch (IllegalArgumentException e){
throw new AxelorException(String.format( I18n.get( IExceptionMessage.EMPLOYEE_NO_BIRTH_DATE ), employee.getName() ), IException.NO_VALUE);
}
}
示例6: getAge
import org.joda.time.Years; //導入方法依賴的package包/類
/**
* Calculates the age of the person between the given birthDate and the toDate
*
* @param fromDate
* @param toDate
* @return
*/
public static int getAge(Date fromDate, Date toDate) {
if (fromDate == null || toDate == null) {
return 0;
}
DateTime bd = new DateTime(fromDate).withTimeAtStartOfDay();
DateTime now = new DateTime(toDate).withTimeAtStartOfDay();
Years age = Years.yearsBetween(bd, now);
return age.getYears();
}
示例7: getAge
import org.joda.time.Years; //導入方法依賴的package包/類
public int getAge() {
Years years = Years.yearsBetween(dateOfBirth, new DateTime());
return years.getYears();
}
示例8: toNonNullString
import org.joda.time.Years; //導入方法依賴的package包/類
@Override
public String toNonNullString(Years value) {
return "" + value.getYears();
}
示例9: toNonNullValue
import org.joda.time.Years; //導入方法依賴的package包/類
@Override
public Integer toNonNullValue(Years value) {
return value.getYears();
}
示例10: years_between_two_dates_in_java_with_joda
import org.joda.time.Years; //導入方法依賴的package包/類
@Test
public void years_between_two_dates_in_java_with_joda () {
DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0);
Years years = Years.yearsBetween(start, end);
int numberOfYears = years.getYears();
assertEquals(1, numberOfYears);
}