当前位置: 首页>>代码示例>>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;未经允许,请勿转载。