本文整理汇总了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());
}
}
示例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);
}
示例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);
}
}
示例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];
}