本文整理汇总了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;
}