當前位置: 首頁>>代碼示例>>Java>>正文


Java Period.getDays方法代碼示例

本文整理匯總了Java中org.joda.time.Period.getDays方法的典型用法代碼示例。如果您正苦於以下問題:Java Period.getDays方法的具體用法?Java Period.getDays怎麽用?Java Period.getDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.Period的用法示例。


在下文中一共展示了Period.getDays方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: prettifyDuration

import org.joda.time.Period; //導入方法依賴的package包/類
private String prettifyDuration(String duration) {
    PeriodFormatter formatter = new PeriodFormatterBuilder()
            .appendDays().appendSuffix("d")
            .appendHours().appendSuffix(":")
            .appendMinutes().appendSuffix(":")
            .appendSeconds().toFormatter();

    Period p = formatter.parsePeriod(duration);

    String day = context.getResources().getString(R.string.day_short);

    if(p.getDays() > 0) {
        return String.format("%d"+ day + " %dh %dm", p.getDays(), p.getHours(), p.getMinutes());
    } else if (p.getHours() > 0) {
        return String.format(Locale.getDefault(), "%dh %dm", p.getHours(), p.getMinutes());
    } else {
        return String.format(Locale.getDefault(), "%dm", p.getMinutes());
    }
}
 
開發者ID:IMSmobile,項目名稱:Fahrplan,代碼行數:20,代碼來源:ConnectionAdapter.java

示例2: formatIntervalDay

import org.joda.time.Period; //導入方法依賴的package包/類
/**
 * Formats a period similar to Oracle INTERVAL DAY TO SECOND data type.<br>
 * For example, the string "-001 18:25:16.766" defines an interval of - 1 day 18 hours 25 minutes 16 seconds and 766 milliseconds
 */
public static String formatIntervalDay(final Period p) {
  long millis = p.getDays() * (long) DateUtility.daysToStandardMillis + DateUtility.millisFromPeriod(p);

  boolean neg = false;
  if (millis < 0) {
    millis = -millis;
    neg = true;
  }

  final int days = (int) (millis / DateUtility.daysToStandardMillis);
  millis = millis % DateUtility.daysToStandardMillis;

  final int hours  = (int) (millis / DateUtility.hoursToMillis);
  millis     = millis % DateUtility.hoursToMillis;

  final int minutes = (int) (millis / DateUtility.minutesToMillis);
  millis      = millis % DateUtility.minutesToMillis;

  final int seconds = (int) (millis / DateUtility.secondsToMillis);
  millis      = millis % DateUtility.secondsToMillis;

  return String.format("%c%03d %02d:%02d:%02d.%03d", neg ? '-':'+', days, hours, minutes, seconds, millis);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:28,代碼來源:DremioStringUtils.java

示例3: writeInterval

import org.joda.time.Period; //導入方法依賴的package包/類
@Override
public void writeInterval(boolean isNull) throws IOException {
  IntervalWriter intervalWriter = writer.interval();
  if(!isNull){
    final Period p = ISOPeriodFormat.standard().parsePeriod(parser.getValueAsString());
    int months = DateUtility.monthsFromPeriod(p);
    int days = p.getDays();
    int millis = DateUtility.millisFromPeriod(p);
    intervalWriter.writeInterval(months, days, millis);
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:12,代碼來源:VectorOutput.java

示例4: 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];
}
 
開發者ID:Applications-Development,項目名稱:SimpleRssReader,代碼行數:54,代碼來源:DateUtils.java


注:本文中的org.joda.time.Period.getDays方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。