本文整理汇总了Java中org.joda.time.Duration.getMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.getMillis方法的具体用法?Java Duration.getMillis怎么用?Java Duration.getMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.Duration
的用法示例。
在下文中一共展示了Duration.getMillis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lengthBetween
import org.joda.time.Duration; //导入方法依赖的package包/类
/**
* 获得两个时间点之间的时间跨度
*
* @param time1
* 开始的时间点
* @param time2
* 结束的时间点
* @param timeUnit
* 跨度的时间单位 see {@link JodaTime}
* (支持的时间单位有DAY,HOUR,MINUTE,SECOND,MILLI)
*/
public static long lengthBetween(DateTime time1, DateTime time2,
DurationFieldType timeUnit) {
Duration duration = Days.daysBetween(time1, time2).toStandardDuration();
if (timeUnit == JodaTime.DAY) {
return duration.getStandardDays();
} else if (timeUnit == JodaTime.HOUR) {
return duration.getStandardHours();
} else if (timeUnit == JodaTime.MINUTE) {
return duration.getStandardMinutes();
} else if (timeUnit == JodaTime.SECOND) {
return duration.getStandardSeconds();
} else if (timeUnit == JodaTime.MILLI) {
return duration.getMillis();
} else {
throw new RuntimeException(
"TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI");
}
}
示例2: getFormattedDate
import org.joda.time.Duration; //导入方法依赖的package包/类
public static Tuple<String, Integer> getFormattedDate(long timeEdited, Context context) {
DateTime dateEdited = new DateTime(timeEdited);
DateTime dateNow = new DateTime();
Duration interval = new Duration(dateEdited, dateNow);
String appendix;
long millisUntilNextUpdate;
long timeElapsedInMillis = interval.getMillis();
if (timeElapsedInMillis < TEN_SECONDS) {
appendix = context.getString(R.string.just_now);
millisUntilNextUpdate = TEN_SECONDS - timeElapsedInMillis;
} else if (timeElapsedInMillis < ONE_MINUTE) {
appendix = context.getString(R.string.less_than_a_minute_ago);
millisUntilNextUpdate = ONE_MINUTE - timeElapsedInMillis;
} else if (timeElapsedInMillis < TWO_MINUTES) {
appendix = context.getString(R.string.one_minute_ago);
millisUntilNextUpdate = TWO_MINUTES - timeElapsedInMillis;
} else if (timeElapsedInMillis < ONE_HOUR) {
appendix = interval.getStandardMinutes() + context.getString(R.string.minutes_ago);
millisUntilNextUpdate = timeElapsedInMillis % ONE_MINUTE;
} else {
if (isOlderThanYesterday(dateEdited, dateNow)) {
appendix = dateEdited.toString(DateTimeFormat.forPattern(FULL_DATE_FORMAT));
millisUntilNextUpdate = UPDATE_NOT_REQUIRED;
} else {
String time = dateEdited.toString(DateTimeFormat.forPattern(HOUR_FORMAT));
millisUntilNextUpdate = new Duration(dateEdited, dateEdited.withTimeAtStartOfDay()
.plusDays(ONE_DAY)).getMillis();
if (isToday(dateEdited, dateNow)) {
appendix = context.getString(R.string.today_at) + time;
} else {
appendix = context.getString(R.string.yesterday_at) + time;
}
}
}
return new Tuple<>(context.getString(R.string.last_edited) + appendix,
(int) millisUntilNextUpdate);
}