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


Java Duration.getMillis方法代碼示例

本文整理匯總了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");
	}
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:30,代碼來源:DateUtils.java

示例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);
}
 
開發者ID:Laaidback,項目名稱:A.scribe,代碼行數:39,代碼來源:DateFormatter.java


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