本文整理汇总了Java中org.joda.time.Period.getMonths方法的典型用法代码示例。如果您正苦于以下问题:Java Period.getMonths方法的具体用法?Java Period.getMonths怎么用?Java Period.getMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.Period
的用法示例。
在下文中一共展示了Period.getMonths方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatIntervalYear
import org.joda.time.Period; //导入方法依赖的package包/类
/**
* Formats a period similar to Oracle INTERVAL YEAR TO MONTH data type<br>
* For example, the string "+21-02" defines an interval of 21 years and 2 months
*/
public static String formatIntervalYear(final Period p) {
long months = p.getYears() * (long) DateUtility.yearsToMonths + p.getMonths();
boolean neg = false;
if (months < 0) {
months = -months;
neg = true;
}
final int years = (int) (months / DateUtility.yearsToMonths);
months = months % DateUtility.yearsToMonths;
return String.format("%c%03d-%02d", neg ? '-':'+', years, months);
}
示例2: monthsFromPeriod
import org.joda.time.Period; //导入方法依赖的package包/类
public static int monthsFromPeriod(Period period){
return (period.getYears() * yearsToMonths) + period.getMonths();
}
示例3: parseDate
import org.joda.time.Period; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String parseDate(final Context context, final Date date) {
final Context ctx = context.getApplicationContext();
final Resources res = ctx.getResources();
final Locale locale;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
locale = res.getConfiguration().getLocales().get(0);
} else {
locale = res.getConfiguration().locale;
}
final DateTime dt = new DateTime(date);
final Period period = new Period(dt.getMillis(), System.currentTimeMillis());
final int[] periodFields = {
period.getYears(), period.getMonths(), period.getWeeks(),
period.getDays(), period.getHours(), period.getMinutes()
};
final String[] dateSpecifierSingular = res.getStringArray(R.array.date_elements_singular);
final String[] dateSpecifierPlural = res.getStringArray(R.array.date_elements_plural);
int i = 0;
for (final int periodField : periodFields) {
if (periodField > 0) {
final String dateSpecifier;
if (periodField > 1) {
dateSpecifier = dateSpecifierPlural[i];
} else {
dateSpecifier = dateSpecifierSingular[i];
}
if (locale.equals(Locale.GERMANY)) {
return String.format("%s %s %s",
ctx.getString(R.string.ago),
periodField, dateSpecifier);
}
return String.format("%s %s %s", periodField, dateSpecifier,
ctx.getString(R.string.ago));
}
i++;
}
return dateSpecifierSingular[i];
}