本文整理匯總了Java中org.joda.time.Years類的典型用法代碼示例。如果您正苦於以下問題:Java Years類的具體用法?Java Years怎麽用?Java Years使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Years類屬於org.joda.time包,在下文中一共展示了Years類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getYearsBetween
import org.joda.time.Years; //導入依賴的package包/類
public static int getYearsBetween(final String date1, final String date2, String format){
try {
final DateTimeFormatter fmt =
DateTimeFormat
.forPattern(format)
.withChronology(
LenientChronology.getInstance(
GregorianChronology.getInstance()));
return Years.yearsBetween(
fmt.parseDateTime(date1),
fmt.parseDateTime(date2)
).getYears();
} catch (Exception ex) {
ex.printStackTrace();
return 0;
}
}
示例2: get_interval
import org.joda.time.Years; //導入依賴的package包/類
private String get_interval(DateTime largerDatetime, DateTime smallerDateTime) throws HydraClientException{
int year_diff = Years.yearsBetween(smallerDateTime, largerDatetime).getYears();
int month_diff = Months.monthsBetween(smallerDateTime, largerDatetime).getMonths();
int day_diff = Days.daysBetween(smallerDateTime, largerDatetime).getDays();
int hour_diff = Hours.hoursBetween(smallerDateTime, largerDatetime).getHours();
int min_diff = Minutes.minutesBetween(smallerDateTime, largerDatetime).getMinutes();
if (year_diff > 0){return year_diff+"YEAR";}
if (month_diff > 0){return month_diff+"MONTH";}
if (day_diff > 0){return day_diff+"DAY";}
if (hour_diff > 0){return hour_diff+"HOUR";}
if (min_diff > 0){return min_diff+"MIN";}
throw new HydraClientException("Could not compute interval between times " + smallerDateTime.toString() + "and" + largerDatetime.toString());
}
示例3: YEARS
import org.joda.time.Years; //導入依賴的package包/類
/**
* Returns the number of years between two dates.
*/
@Function("YEARS")
@FunctionParameters({
@FunctionParameter("startDate"),
@FunctionParameter("endDate")})
public Integer YEARS(Object startDate, Object endDate){
Date startDateObj = convertDateObject(startDate);
if(startDateObj==null) {
logCannotConvertToDate();
return null;
}
Date endDateObj = convertDateObject(endDate);
if(endDateObj==null){
logCannotConvertToDate();
return null;
}
else{
LocalDate dt1=new LocalDate(startDateObj);
LocalDate dt2=new LocalDate(endDateObj);
return Years.yearsBetween(dt1, dt2).getYears();
}
}
示例4: formatDate
import org.joda.time.Years; //導入依賴的package包/類
@Override
protected String formatDate(DateTime now, DateTime then) {
if (dateFormat == null)
buildDateFormat();
StringBuilder builder = new StringBuilder();
if (hasFormat(WEEKDAY) && now.get(omitWeekday) == then.get(omitWeekday))
builder.append(weekdayFormat.print(then));
if (hasFormat(DAYS | MONTHS)) {
if (builder.length() > 0)
builder.append(", ");
builder.append(dateFormat.print(then));
}
if (hasFormat(YEARS) && Years.yearsBetween(now, then).getYears() != 0)
builder.append(yearFormat.print(then));
if (hasFormat(TIME) && now.get(omitTime) == then.get(omitTime)) {
builder.append(", ");
builder.append(formatTime(now, then));
}
return builder.toString();
}
示例5: transform
import org.joda.time.Years; //導入依賴的package包/類
@Override
public Integer[] transform(final InputRow inputRow) {
final Integer[] result = new Integer[2];
final Date date = inputRow.getValue(dateColumn);
if (date != null) {
final long diffMillis = today.getTime() - date.getTime();
final int diffDays = (int) (diffMillis / (1000 * 60 * 60 * 24));
result[0] = diffDays;
// use Joda time to easily calculate the diff in years
final int diffYears = Years.yearsBetween(new DateTime(date), new DateTime(today)).getYears();
result[1] = diffYears;
}
return result;
}
示例6: create
import org.joda.time.Years; //導入依賴的package包/類
@Override
public Object create(Object request, SpecimenContext context) {
if (!(request instanceof SpecimenType)) {
return new NoSpecimen();
}
SpecimenType type = (SpecimenType) request;
if (!BaseSingleFieldPeriod.class.isAssignableFrom(type.getRawType())) {
return new NoSpecimen();
}
Duration duration = (Duration) context.resolve(Duration.class);
if (type.equals(Seconds.class)) return Seconds.seconds(Math.max(1, (int) duration.getStandardSeconds()));
if (type.equals(Minutes.class)) return Minutes.minutes(Math.max(1, (int) duration.getStandardMinutes()));
if (type.equals(Hours.class)) return Hours.hours(Math.max(1, (int) duration.getStandardHours()));
if (type.equals(Days.class)) return Days.days(Math.max(1, (int) duration.getStandardDays()));
if (type.equals(Weeks.class)) return Weeks.weeks(Math.max(1, (int) duration.getStandardDays() / 7));
if (type.equals(Months.class)) return Months.months(Math.max(1, (int) duration.getStandardDays() / 30));
if (type.equals(Years.class)) return Years.years(Math.max(1, (int) duration.getStandardDays() / 365));
return new NoSpecimen();
}
示例7: transform
import org.joda.time.Years; //導入依賴的package包/類
@Override
public Integer[] transform(InputRow inputRow) {
Integer[] result = new Integer[2];
Date date = inputRow.getValue(dateColumn);
if (date != null) {
long diffMillis = today.getTime() - date.getTime();
int diffDays = (int) (diffMillis / (1000 * 60 * 60 * 24));
result[0] = diffDays;
// use Joda time to easily calculate the diff in years
int diffYears = Years.yearsBetween(new DateTime(date), new DateTime(today)).getYears();
result[1] = diffYears;
}
return result;
}
示例8: 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();
}
示例9: 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();
}
示例10: findDifferenceBetween
import org.joda.time.Years; //導入依賴的package包/類
public static Integer findDifferenceBetween(Calendar start, Calendar end, String type){
if(type == null || type.trim().isEmpty()){
throw new IllegalArgumentException("You must inform a diff type (MONTHS, YEARS or DAYS).");
}
DateTime dtStart = new DateTime(start.getTimeInMillis());
DateTime dtEnd = new DateTime(end.getTimeInMillis());
if(MONTHS.equals(type)){
return Months.monthsBetween(dtStart, dtEnd).getMonths();
}
else{
if(YEARS.equals(type)){
return Years.yearsBetween(dtStart, dtEnd).getYears();
}
else{
return Days.daysBetween(dtStart, dtEnd).getDays();
}
}
}
示例11: getTokenDurationAsStringList
import org.joda.time.Years; //導入依賴的package包/類
@NonNull
public static List getTokenDurationAsStringList(LocalDate expiry, String year, String month, String day) {// Get months
LocalDate start = new LocalDate(DateTime.now());
int years = Years.yearsBetween(start, expiry).getYears();
// Subtract this number of years from the end date so we can calculate days
expiry = expiry.minusYears(years);
int months = Months.monthsBetween(start, expiry).getMonths();
// Subtract this number of months from the end date so we can calculate days
expiry = expiry.minusMonths(months);
// Get days
int days = Days.daysBetween(start, expiry).getDays();
String y = null, m = null, d = null;
List list = new ArrayList();
if (years > 0) {
y = years + year;
list.add(y);
}
if (months > 0) {
m = months + month;
list.add(m);
}
if (days > 0) {
d = days + day;
list.add(d);
}
return list;
}
示例12: 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()));
}
示例13: futureDateTime
import org.joda.time.Years; //導入依賴的package包/類
public static DateTime futureDateTime() {
DateTime now = DateTime.now();
long min = now.getMillis();
long max = now.plus(Years.TWO).getMillis();
double random = randomDouble(min, max);
return new DateTime(Double.valueOf(random).longValue());
}
示例14: pastDateTime
import org.joda.time.Years; //導入依賴的package包/類
public static DateTime pastDateTime() {
DateTime now = DateTime.now();
long min = now.minus(Years.TWO).getMillis();
long max = now.getMillis();
double random = randomDouble(min, max);
return new DateTime(Double.valueOf(random).longValue());
}
示例15: CreditCard
import org.joda.time.Years; //導入依賴的package包/類
public CreditCard(CreditCardNumber number, String cardHolderName, Months expiryMonth, Years expiryYear) {
super();
this.number = number;
this.cardHolderName = cardHolderName;
this.expiryMonth = expiryMonth;
this.expiryYear = expiryYear;
}