本文整理匯總了Java中org.joda.time.Years.yearsBetween方法的典型用法代碼示例。如果您正苦於以下問題:Java Years.yearsBetween方法的具體用法?Java Years.yearsBetween怎麽用?Java Years.yearsBetween使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.Years
的用法示例。
在下文中一共展示了Years.yearsBetween方法的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: onCreate
import org.joda.time.Years; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_knell);
ButterKnife.bind(this);
Birthday birthday = getBirthdayManager().get();
DateTime birDateTime = new DateTime(birthday.year, birthday.month, birthday.day, 0, 0);
Days days = Days.daysBetween(birDateTime, DateTime.now());
Hours hours = Hours.hoursBetween(birDateTime, DateTime.now());
Minutes minutes = Minutes.minutesBetween(birDateTime, DateTime.now());
Weeks weeks = Weeks.weeksBetween(birDateTime, DateTime.now());
Years years = Years.yearsBetween(birDateTime, DateTime.now());
Months months = Months.monthsBetween(birDateTime, DateTime.now());
Timber.d("onCreate: 年:%d", years.getYears());
Timber.d("onCreate: 月:%d", months.getMonths());
Timber.d("onCreate: 周:%d", weeks.getWeeks());
Timber.d("onCreate: 天數為:%d", days.getDays());
Timber.d("onCreate: 小時數為:%d", hours.getHours());
Timber.d("onCreate: 分鍾數為:%d", minutes.getMinutes());
tvYear.setText(String.valueOf(years.getYears()));
tvMonth.setText(String.valueOf(months.getMonths()));
tvWeek.setText(String.valueOf(weeks.getWeeks()));
tvDay.setText(String.valueOf(days.getDays()));
tvHour.setText(String.valueOf(hours.getHours()));
tvMinute.setText(String.valueOf(minutes.getMinutes()));
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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();
}
示例8: age
import org.joda.time.Years; //導入方法依賴的package包/類
public static int age(final DateTime birthday) {
DateTime _now = DateTime.now();
Years _yearsBetween = Years.yearsBetween(birthday, _now);
DurationFieldType _years = DurationFieldType.years();
return _yearsBetween.get(_years);
}
示例9: getAge
import org.joda.time.Years; //導入方法依賴的package包/類
public int getAge() {
Years years = Years.yearsBetween(dateOfBirth, new DateTime());
return years.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);
}