public static String getTimestamp(long duration) {
PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
.appendYears().appendSuffix("y ")
.appendMonths().appendSuffix("m ")
.appendWeeks().appendSuffix("w ")
.appendDays().appendSuffix("d ")
.appendHours().appendSuffix("h ")
.appendMinutes().appendSuffix("m ")
.appendSeconds().appendSuffix("s")
.toFormatter();
return periodFormatter.print(new Period(new Duration(duration)).normalizedStandard());
}
java类org.joda.time.format.PeriodFormatter的实例源码
DiscordUtil.java 文件源码
项目:DiscordBot
阅读 22
收藏 0
点赞 0
评论 0
HostServicePropertiesImpl.java 文件源码
项目:robobee-osgi
阅读 23
收藏 0
点赞 0
评论 0
public Period getPeriodProperty(String key, PeriodFormatter formatter,
ContextProperties defaults) {
Period value = typedProperties.getPeriodProperty(key, formatter);
if (value != null) {
return value;
} else {
return typedAllPropertiesFactory.create(defaults)
.getPeriodProperty(key);
}
}
HostServicePropertiesImpl.java 文件源码
项目:robobee-osgi
阅读 137
收藏 0
点赞 0
评论 0
public Duration getDurationProperty(String key, PeriodFormatter formatter,
ContextProperties defaults) {
Duration value = typedProperties.getDurationProperty(key, formatter);
if (value != null) {
return value;
} else {
return typedAllPropertiesFactory.create(defaults)
.getDurationProperty(key, formatter);
}
}
DateUtils.java 文件源码
项目:motu
阅读 27
收藏 0
点赞 0
评论 0
/**
* String to period.
*
* @param s the s
* @return the period
* @throws MotuConverterException the motu converter exception
*/
public static Period stringToPeriod(String s) throws MotuConverterException {
if (LOG.isDebugEnabled()) {
LOG.debug("stringToPeriod(String) - entering");
}
Period period = null;
StringBuffer stringBuffer = new StringBuffer();
for (PeriodFormatter periodFormatter : DateUtils.PERIOD_FORMATTERS.values()) {
try {
period = periodFormatter.parsePeriod(s);
} catch (IllegalArgumentException e) {
// LOG.error("stringToPeriod(String)", e);
stringBuffer.append(e.getMessage());
stringBuffer.append("\n");
}
if (period != null) {
break;
}
}
if (period == null) {
throw new MotuConverterException(
String.format("Cannot convert '%s' to Period. Format '%s' is not valid.\nAcceptable format are '%s'",
s,
stringBuffer.toString(),
DateUtils.PERIOD_FORMATTERS.keySet().toString()));
}
if (LOG.isDebugEnabled()) {
LOG.debug("stringToPeriod(String) - exiting");
}
return period;
}
StartPauseButtonListener.java 文件源码
项目:xstreamer
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void run() {
Duration duration = new Duration(Activator.getCountDownTime());
if (duration.getMillis() <= 0) {
countDownTimer.cancel();
return;
}
duration = duration.minus(1000);
Activator.setCountDownTime(duration.getMillis());
final Period periodLeft = duration.toPeriod();
PeriodFormatter formatter = new PeriodFormatterBuilder().minimumPrintedDigits(2).printZeroAlways().appendHours()
.appendSeparator(":").minimumPrintedDigits(2).printZeroAlways().appendMinutes().appendSeparator(":")
.minimumPrintedDigits(2).printZeroAlways().appendSeconds().toFormatter();
String formattedTime = periodLeft.toString(formatter);
Runnable updateUi = () -> {
int hours = periodLeft.getHours();
int mins = periodLeft.getMinutes();
int seconds = periodLeft.getSeconds();
NumberFormat numberFormat = new DecimalFormat("00");
CountDownTimerPage.hourCountDownLabel.setText(numberFormat.format(hours));
CountDownTimerPage.minuteCountDownLabel.setText(numberFormat.format(mins));
CountDownTimerPage.secondsCountDownLabel.setText(numberFormat.format(seconds));
};
Display.getDefault().asyncExec(updateUi);
Job countDownJob = new CountDownJob("countdown", formattedTime);
countDownJob.schedule();
}
DurationSerializer.java 文件源码
项目:playground
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void serialize(
final Duration duration,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (duration == null)
{
jgen.writeNull();
return;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
jgen.writeString(duration.toPeriod().toString(formatter));
}
DurationDeserializer.java 文件源码
项目:playground
阅读 29
收藏 0
点赞 0
评论 0
@Override
public Duration deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws JsonParseException, IOException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Duration(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
return formatter.parsePeriod(str).toStandardDuration();
}
throw ctxt.mappingException(Duration.class);
}
SAXProcessor.java 文件源码
项目:SAX
阅读 32
收藏 0
点赞 0
评论 0
/**
* Generic method to convert the milliseconds into the elapsed time string.
*
* @param start Start timestamp.
* @param finish End timestamp.
* @return String representation of the elapsed time.
*/
public static String timeToString(long start, long finish) {
Duration duration = new Duration(finish - start); // in milliseconds
PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d")
.appendHours().appendSuffix("h").appendMinutes().appendSuffix("m").appendSeconds()
.appendSuffix("s").appendMillis().appendSuffix("ms").toFormatter();
return formatter.print(duration.toPeriod());
}
AvroHdfsTimePartitionedWriter.java 文件源码
项目:Gobblin
阅读 23
收藏 0
点赞 0
评论 0
private Optional<Long> getEarliestAllowedTimestamp() {
if (!this.properties.contains(TIME_PARTITIONED_WRITER_MAX_TIME_AGO)) {
return Optional.<Long> absent();
} else {
DateTime currentTime = new DateTime(this.timeZone);
PeriodFormatter periodFormatter = getPeriodFormatter();
String maxTimeAgoStr = this.properties.getProp(TIME_PARTITIONED_WRITER_MAX_TIME_AGO);
Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr);
return Optional.of(currentTime.minus(maxTimeAgo).getMillis());
}
}
FeedRecyclerAdapter.java 文件源码
项目:FriendCaster
阅读 27
收藏 0
点赞 0
评论 0
private String getFormattedDuration(int seconds) {
Period period = new Period(Seconds.seconds(seconds));
PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
.printZeroAlways()
.minimumPrintedDigits(2)
.appendHours()
.appendSeparator(":")
.appendMinutes()
.appendSeparator(":")
.appendSeconds()
.toFormatter();
return periodFormatter.print(period.normalizedStandard());
}