本文整理匯總了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];
}