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


Java PeriodFormatterBuilder類代碼示例

本文整理匯總了Java中org.joda.time.format.PeriodFormatterBuilder的典型用法代碼示例。如果您正苦於以下問題:Java PeriodFormatterBuilder類的具體用法?Java PeriodFormatterBuilder怎麽用?Java PeriodFormatterBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: formatDuration

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
public static String formatDuration(long duration)
{
	// Using Joda Time
	DateTime now = new DateTime(); // Now
	DateTime plus = now.plus(new Duration(duration * 1000));

	// Define and calculate the interval of time
	Interval interval = new Interval(now.getMillis(), plus.getMillis());
	Period period = interval.toPeriod(PeriodType.time());

	// Define the period formatter for pretty printing
	String ampersand = " & ";
	PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
		.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
		.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();

	return pf.print(period).trim();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:EchoUtils.java

示例2: prettifyDuration

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的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

示例3: timeStringSmallScale

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
/**
 * Internal method to convert a period of lesser than month scales
 *
 * @param period The period to format
 * @return A relative time string describing the period
 */
private String timeStringSmallScale(Period period) {
  PeriodFormatterBuilder builder = new PeriodFormatterBuilder()
      .printZeroNever()
      .appendDays()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
      .appendSeparator(", ")
      .appendHours()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_HOUR), i18n.getString(TIMEUNIT_HOURS))
      .appendSeparator(", ")
      .appendMinutes()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_MINUTE), i18n.getString(TIMEUNIT_MINUTES));

  if (period.toStandardHours().getHours() == 0) {
    // Do not append seconds if the period is larger than one hour
    builder.appendSeparator(", ")
        .appendSeconds()
        .appendSuffix(" ")
        .appendSuffix(i18n.getString(TIMEUNIT_SECOND), i18n.getString(TIMEUNIT_SECONDS));
  }

  return builder.toFormatter().print(period);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:32,代碼來源:TimeFormatter.java

示例4: timeStringLargeScale

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
/**
 * Internal method to convert a period of greater than month scales
 *
 * @param period The period to format
 * @return A relative time string describing the period
 */
private String timeStringLargeScale(Period period) {
  return new PeriodFormatterBuilder()
      .printZeroNever()
      .appendYears()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_YEAR), i18n.getString(TIMEUNIT_YEARS))
      .appendSeparator(", ")
      .appendMonths()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_MONTH), i18n.getString(TIMEUNIT_MONTHS))
      .appendSeparator(", ")
      .appendDays()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
      .toFormatter()
      .print(period);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:24,代碼來源:TimeFormatter.java

示例5: TimestampPickerController

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
@VisibleForTesting
public TimestampPickerController(Locale locale, boolean isStartCrop, String negativePrefix,
        String hourMinuteDivider, String minuteSecondDivider,
        OnTimestampErrorListener errorListener) {
    mLocale = locale;
    mIsStartCrop = isStartCrop;
    mErrorListener = errorListener;
    mNegativePrefix = negativePrefix;
    // Builds the formatter, which will be used to read and write timestamp strings.
    mPeriodFormatter = new PeriodFormatterBuilder()
            .rejectSignedValues(true)  // Applies to all fields
            .printZeroAlways()  // Applies to all fields
            .appendHours()
            .appendLiteral(hourMinuteDivider)
            .minimumPrintedDigits(2)  // Applies to minutes and seconds
            .appendMinutes()
            .appendLiteral(minuteSecondDivider)
            .appendSecondsWithMillis()
            .toFormatter()
            .withLocale(mLocale);
}
 
開發者ID:google,項目名稱:science-journal,代碼行數:22,代碼來源:TimestampPickerController.java

示例6: calculateAge

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
private static String calculateAge(DateTime epDate) {

		Period period;
		if (epDate.isBefore(new DateTime())) {
			period = new Period(epDate, new DateTime());
		} else {
			period = new Period(new DateTime(), epDate);
		}

		PeriodFormatter formatter = new PeriodFormatterBuilder()
				.appendYears().appendSuffix("y")
				.appendMonths().appendSuffix("m")
				.appendWeeks().appendSuffix("w")
				.appendDays().appendSuffix("d ")
				.appendHours().appendSuffix("h")
				.appendMinutes().appendSuffix("m")
				.printZeroNever().toFormatter();

		return formatter.print(period);
	}
 
開發者ID:drftpd-ng,項目名稱:drftpd3,代碼行數:21,代碼來源:TvMazeUtils.java

示例7: dateHelper

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
private Helper<Long> dateHelper() {
    return new Helper<Long>() {
        public CharSequence apply(Long arg0, Options arg1) throws IOException {
            PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" d : ")
                .appendHours()
                .appendSuffix(" h : ")
                .appendMinutes()
                .appendSuffix(" m : ")
                .appendSeconds()
                .appendSuffix(" s : ")
                .appendMillis()
                .appendSuffix(" ms")
                .toFormatter();
            return formatter.print(new Period((arg0 * 1) / 1000000));
        }
    };
}
 
開發者ID:web-innovate,項目名稱:bootstraped-multi-test-results-report,代碼行數:20,代碼來源:Helpers.java

示例8: VanitygenPanel

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
public VanitygenPanel() {
    super(MessageKey.vanity_address, AwesomeIcon.VIMEO_SQUARE);
    passwordGetter = new PasswordPanel.PasswordGetter(VanitygenPanel.this);
    remainingTimeFormatter = new PeriodFormatterBuilder().printZeroNever().appendYears().appendSuffix
            (LocaliserUtils.getString("vanity_time_year_suffix")).appendMonths().appendSuffix
            (LocaliserUtils.getString("vanity_time_month_suffix")).appendDays().appendSuffix
            (LocaliserUtils.getString("vanity_time_day_suffix")).appendHours().appendSuffix
            (LocaliserUtils.getString("vanity_time_hour_suffix")).appendMinutes()
            .appendSuffix(LocaliserUtils.getString("vanity_time_minute_suffix"))
            .appendSeconds().appendSuffix(LocaliserUtils.getString
                    ("vanity_time_second_suffix")).toFormatter();
    setOkAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isInCalculatingView) {
                generateAddress();
            } else {
                showCalculate();
            }
        }
    });
    if (OSUtils.isWindows() && SystemUtil.isSystem32()) {
        ecKeyType = BitherSetting.ECKeyType.UNCompressed;
    }
}
 
開發者ID:bither,項目名稱:bither-desktop-java,代碼行數:26,代碼來源:VanitygenPanel.java

示例9: formattedDuration

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
public static String formattedDuration(long duration) {

        PeriodFormatter hoursMinutes = new PeriodFormatterBuilder()
                .appendHours()
                .appendSuffix(" hr", " hrs")
                .appendSeparator(" ")
                .appendMinutes()
                .appendSuffix(" min", " mins")
                .appendSeparator(" ")
                .appendSeconds()
                .appendSuffix(" sec", " secs")
                .toFormatter();
        Period p = new Period(duration);

        return hoursMinutes.print(p);
    }
 
開發者ID:eyedol,項目名稱:birudo,代碼行數:17,代碼來源:AppUtil.java

示例10: getGatewayDeploymentsBackupAgeLimit

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
public long getGatewayDeploymentsBackupAgeLimit() {
    PeriodFormatter f = (new PeriodFormatterBuilder()).appendDays().toFormatter();
    String s = this.get("gateway.deployment.backup.ageLimit", "-1");

    long d;
    try {
        Period e = Period.parse(s, f);
        d = e.toStandardDuration().getMillis();
        if (d < 0L) {
            d = -1L;
        }
    } catch (Exception var6) {
        d = -1L;
    }

    return d;
}
 
開發者ID:sakserv,項目名稱:hadoop-mini-clusters,代碼行數:18,代碼來源:LocalGatewayConfig.java

示例11: JodaFormatter

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
/**
 * Default constructor.
 */
public JodaFormatter() {

    PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder().appendYears().appendSuffix(" year", " years")
        .appendMonths().appendSuffix(" month", " months")
        .appendWeeks().appendSuffix(" week", " weeks")
        .appendDays().appendSuffix(" day", " days")
        .appendHours().appendSuffix(" hour", " hours")
        .appendMinutes().appendSuffix(" minute", " minutes")
        .appendSeconds().appendSuffix(" second", " seconds");

    periodParser = periodFormatterBuilder.toParser();
    periodFormatter = periodFormatterBuilder.toFormatter();

    dateTimeFormatter = ISODateTimeFormat.dateTime();
}
 
開發者ID:motech,項目名稱:motech,代碼行數:19,代碼來源:JodaFormatter.java

示例12: periodHourMinBased

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
public static String periodHourMinBased(long secDuration) {
    PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
    PeriodFormatter formatter = null;
    String minutesAbbr = ToggApp.getApplication().getString(
            R.string.minutes_abbr);
    ;
    String hoursAbbr = ToggApp.getApplication().getString(
            R.string.hours_abbr);
    ;

    formatter = builder.printZeroAlways().minimumPrintedDigits(1)
            .appendHours().appendLiteral(" " + hoursAbbr + " ")
            .minimumPrintedDigits(2).appendMinutes()
            .appendLiteral(" " + minutesAbbr).toFormatter();

    Period period = new Period(secDuration * 1000);

    return formatter.print(period.normalizedStandard());
}
 
開發者ID:darrillaga,項目名稱:togg,代碼行數:20,代碼來源:DateTimeFormatter.java

示例13: providePeriodFormatter

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
@Singleton
@Provides
public PeriodFormatter providePeriodFormatter(Dictionary<String> dictionary) {
    return new PeriodFormatterBuilder()
            .appendYears()
            .appendSuffix(" " + dictionary.getTranslation("year"), " " + dictionary.getTranslation("years"))
            .appendSeparator(" ")
            .appendMonths()
            .appendSuffix(" " + dictionary.getTranslation("month"), " " + dictionary.getTranslation("months"))
            .appendSeparator(" ")
            .appendDays()
            .appendSuffix(" " + dictionary.getTranslation("day"), " " + dictionary.getTranslation("days"))
            .appendSeparator(" ")
            .appendMinutes()
            .appendSuffix(" " + dictionary.getTranslation("minute"), " " + dictionary.getTranslation("minutes"))
            .appendSeparator(" ")
            .appendSeconds()
            .appendSuffix(" " + dictionary.getTranslation("second"), " " + dictionary.getTranslation("seconds"))
            .toFormatter();
}
 
開發者ID:mc-societies,項目名稱:societies,代碼行數:21,代碼來源:SocietiesModule.java

示例14: postFailureBuild

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
private void postFailureBuild(SRunningBuild build )
{
    String message = "";

    PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
            .printZeroRarelyFirst()
            .appendHours()
            .appendSuffix(" hour", " hours")
            .appendSeparator(" ")
            .printZeroRarelyLast()
            .appendMinutes()
            .appendSuffix(" minute", " minutes")
            .appendSeparator(" and ")
            .appendSeconds()
            .appendSuffix(" second", " seconds")
            .toFormatter();

    Duration buildDuration = new Duration(1000*build.getDuration());

    message = String.format("Project '%s' build failed! ( %s )" , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));

    postToSlack(build, message, false);
}
 
開發者ID:Tapadoo,項目名稱:TCSlackNotifierPlugin,代碼行數:24,代碼來源:SlackServerAdapter.java

示例15: processSuccessfulBuild

import org.joda.time.format.PeriodFormatterBuilder; //導入依賴的package包/類
private void processSuccessfulBuild(SRunningBuild build) {

        String message = "";

        PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
                    .printZeroRarelyFirst()
                    .appendHours()
                    .appendSuffix(" hour", " hours")
                    .appendSeparator(" ")
                    .printZeroRarelyLast()
                    .appendMinutes()
                    .appendSuffix(" minute", " minutes")
                    .appendSeparator(" and ")
                    .appendSeconds()
                    .appendSuffix(" second", " seconds")
                    .toFormatter();

        Duration buildDuration = new Duration(1000*build.getDuration());

        message = String.format("Project '%s' built successfully in %s." , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));

        postToSlack(build, message, true);
    }
 
開發者ID:Tapadoo,項目名稱:TCSlackNotifierPlugin,代碼行數:24,代碼來源:SlackServerAdapter.java


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