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


Java DateTime.getMillis方法代碼示例

本文整理匯總了Java中org.joda.time.DateTime.getMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTime.getMillis方法的具體用法?Java DateTime.getMillis怎麽用?Java DateTime.getMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.DateTime的用法示例。


在下文中一共展示了DateTime.getMillis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: idOfClosest

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static Integer idOfClosest(final List<DateTime> list, final DateTime key, final int low, final int high) {
    // Cas particuliers
    if (list == null || list.isEmpty() || key == null || low > high) {
        return null;
    }
    // Evacuation des cas où la valeur serait hors de l'intervalle -----------
    if (list.size() == 1) {
        return 0;
    }
    if (list.get(low).getMillis() >= key.getMillis()) {
        return low;
    }
    if (list.get(high).getMillis() <= key.getMillis()) {
        return high;
    }

    int idx = binarySearch(list, key, low, high);
    if (idx < 0) {
        idx = -(idx) - 1;
        if (idx != 0 && idx < list.size()) {
            return (key.getMillis()  - list.get(idx - 1).getMillis()  <= list.get(idx).getMillis() - key.getMillis() ) ? idx - 1 : idx;
        }
        return null;
    }
    return idx;
}
 
開發者ID:iapafoto,項目名稱:DicomViewer,代碼行數:27,代碼來源:SortedListTools.java

示例2: formatDuration

import org.joda.time.DateTime; //導入方法依賴的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

示例3: ShowFilesCommandResult

import org.joda.time.DateTime; //導入方法依賴的package包/類
public ShowFilesCommandResult(String name,
                              boolean isDirectory,
                              boolean isFile,
                              long length,
                              String owner,
                              String group,
                              String permissions,
                              long accessTime,
                              long modificationTime) {
  this.name = name;
  this.isDirectory = isDirectory;
  this.isFile = isFile;
  this.length = length;
  this.owner = owner;
  this.group = group;
  this.permissions = permissions;

  // Get the timestamp in UTC because Drill's internal TIMESTAMP stores time in UTC
  DateTime at = new DateTime(accessTime).withZoneRetainFields(DateTimeZone.UTC);
  this.accessTime = new Timestamp(at.getMillis());

  DateTime mt = new DateTime(modificationTime).withZoneRetainFields(DateTimeZone.UTC);
  this.modificationTime = new Timestamp(mt.getMillis());
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:25,代碼來源:ShowFilesCommandResult.java

示例4: waitForAssignmentDate

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static void waitForAssignmentDate(DateTimeZone dateTimeZone, DateTime date) {
    DateTime currentTime = new DateTime(dateTimeZone);
    DateTime dateWithTimeZone = date.withZoneRetainFields(dateTimeZone);
    if (dateWithTimeZone.getMillis() > currentTime.getMillis()) {
        TestUtils.waitForSomeTime((int) (dateWithTimeZone.getMillis() - currentTime.getMillis()), "Wait for date");
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:8,代碼來源:DateUtils.java

示例5: getFormattedTimeInstagram

import org.joda.time.DateTime; //導入方法依賴的package包/類
private String getFormattedTimeInstagram(Date data){
    DateTime d1 = new DateTime(data);
    DateTime d2 = DateTime.now();
    long difference = d2.getMillis() - d1.getMillis();
    DateTime d3 = new DateTime(difference);
    long days = TimeUnit.MILLISECONDS.toDays(d3.getMillis());
    long hours = TimeUnit.MILLISECONDS.toHours(d3.getMillis());
    String out  = "";
    if (hours < 24){
        out =  "HÁ " + String.valueOf(hours) + " HORAS.";
        if (hours < 0) {
            //TODO tentar entender esse bug, enquanto isso, gambiarra rs
            out = "5 DE JUNHO DE 2017";
        }
    } else if (days < 8) {
        out = "HÁ " +  String.valueOf(days) + " DIAS.";
    } else {
        SimpleDateFormat format = new SimpleDateFormat("d,MMMM,yyyy", new Locale("pt", "BR"));
        format.setTimeZone(TimeZone.getDefault());
        out = format.format(data);
        out = out.replace(",", " DE ");
        //TODO: corrigir espaçamento no layout e colocar tudo em maiuscula com semparador "DE"
    }
    out = out.toUpperCase();
    out = out.replace(" DE 2017", "");
    return out;
}
 
開發者ID:secompufscar,項目名稱:app_secompufscar,代碼行數:28,代碼來源:InstagramAdapter.java

示例6: convertDateTime

import org.joda.time.DateTime; //導入方法依賴的package包/類
private Double convertDateTime(DateTime dateTime) {
    if (dateTime == null) {
        return null;
    } else {
        return (double) dateTime.getMillis();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:8,代碼來源:DateRangeAggregationBuilder.java

示例7: testExpression_CustomTimeZoneInSetting

import org.joda.time.DateTime; //導入方法依賴的package包/類
public void testExpression_CustomTimeZoneInSetting() throws Exception {
    DateTimeZone timeZone;
    int hoursOffset;
    int minutesOffset = 0;
    if (randomBoolean()) {
        hoursOffset = randomIntBetween(-12, 14);
        timeZone = DateTimeZone.forOffsetHours(hoursOffset);
    } else {
        hoursOffset = randomIntBetween(-11, 13);
        minutesOffset = randomIntBetween(0, 59);
        timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset);
    }
    DateTime now;
    if (hoursOffset >= 0) {
        // rounding to next day 00:00
        now = DateTime.now(UTC).plusHours(hoursOffset).plusMinutes(minutesOffset).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    } else {
        // rounding to today 00:00
        now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    }
    Settings settings = Settings.builder()
            .put("date_math_expression_resolver.default_time_zone", timeZone.getID())
            .build();
    DateMathExpressionResolver expressionResolver = new DateMathExpressionResolver(settings);
    Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis());
    List<String> results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{YYYY.MM.dd}}>"));
    assertThat(results.size(), equalTo(1));
    logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0));
    assertThat(results.get(0), equalTo(".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.withZone(timeZone))));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:DateMathExpressionResolverTests.java

示例8: getCurrentTimeCloseToPrevInterval

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public final long getCurrentTimeCloseToPrevInterval() {
    long keepMinute = System.currentTimeMillis() / interval * interval;
    DateTime dt = new DateTime(keepMinute);
    int min = dt.getMinuteOfHour();
    min = getPrevIntervalMinute(min);
    dt = dt.minuteOfHour().setCopy(min);
    return dt.getMillis();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:10,代碼來源:CDNCacheImpl.java

示例9: convertTimestampFromStr

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static Timestamp convertTimestampFromStr(String dateStr)
{
	if(StringUtils.isEmpty(dateStr))
	{
		return null;
	}
	
	DateTime dt = parseDate(dateStr);
	
	return new Timestamp(dt.getMillis());
	
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:13,代碼來源:DateUtils.java

示例10: getMilliSecondOfDate

import org.joda.time.DateTime; //導入方法依賴的package包/類
/**
 * 獲取指定日期的當天的任意一毫秒
 *
 * @param date 指定的日期
 * @return
 */
public static long getMilliSecondOfDate(@NotNull Date date, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) {
    Objects.requireNonNull(date, "date must not null");
    DateTime dateTime = new DateTime(date);
    dateTime = dateTime.withHourOfDay(hourOfDay).withMinuteOfHour(minuteOfHour).withSecondOfMinute(secondOfMinute).withMillisOfSecond(millisOfSecond);
    return dateTime.getMillis();
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:13,代碼來源:DateCalculator.java

示例11: alignRangeBoundary

import org.joda.time.DateTime; //導入方法依賴的package包/類
/**
 For YEARS, MONTHS, WEEKS, DAYS:
 Computes the timestamp of the first millisecond of the day
 of the timestamp.
 For HOURS,
 Computes the timestamp of the first millisecond of the hour
 of the timestamp.
 For MINUTES,
 Computes the timestamp of the first millisecond of the minute
 of the timestamp.
 For SECONDS,
 Computes the timestamp of the first millisecond of the second
 of the timestamp.
 For MILLISECONDS,
 returns the timestamp

 @param timestamp
 @return
 */
@SuppressWarnings("fallthrough")
private long alignRangeBoundary(long timestamp)
{
	DateTime dt = new DateTime(timestamp, m_timeZone);
	TimeUnit tu = m_sampling.getUnit();
	switch (tu)
	{
		case YEARS:
			dt = dt.withDayOfYear(1).withMillisOfDay(0);
			break;
		case MONTHS:
			dt = dt.withDayOfMonth(1).withMillisOfDay(0);
			break;
		case WEEKS:
			dt = dt.withDayOfWeek(1).withMillisOfDay(0);
			break;
		case DAYS:
		case HOURS:
		case MINUTES:
		case SECONDS:
			dt = dt.withHourOfDay(0);
			dt = dt.withMinuteOfHour(0);
			dt = dt.withSecondOfMinute(0);
		default:
			dt = dt.withMillisOfSecond(0);
			break;
	}
	return dt.getMillis();
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:49,代碼來源:RangeAggregator.java

示例12: setMinAndMax

import org.joda.time.DateTime; //導入方法依賴的package包/類
/**
 * Changement des bornes de l'animation
 * @param limitMin
 * @param limitMax 
 */
public void setMinAndMax(final DateTime limitMin, final DateTime limitMax) {
    if (!minLimitDragging && !minLimitSelected) {
        this.dateMinAsValue = (limitMin != null) ? (double)limitMin.getMillis() : null;
    }
    if (!maxLimitDragging && !maxLimitSelected) {
        this.dateMaxAsValue = (limitMax != null) ? (double)limitMax.getMillis() : null;
    }
}
 
開發者ID:iapafoto,項目名稱:DicomViewer,代碼行數:14,代碼來源:SliderTimeComponent.java

示例13: dateStringToDays

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static int dateStringToDays(String source) throws MarshalException
{
    // Raw day value in unsigned int form, epoch @ 2^31
    if (rawPattern.matcher(source).matches())
    {
        try
        {
            long result = Long.parseLong(source);

            if (result < 0 || result > maxSupportedDays)
                throw new NumberFormatException("Input out of bounds: " + source);

            // Shift > epoch days into negative portion of Integer result for byte order comparability
            if (result >= Integer.MAX_VALUE)
                result -= byteOrderShift;

            return (int) result;
        }
        catch (NumberFormatException e)
        {
            throw new MarshalException(String.format("Unable to make unsigned int (for date) from: '%s'", source), e);
        }
    }

    // Attempt to parse as date string
    try
    {
        DateTime parsed = formatter.parseDateTime(source);
        long millis = parsed.getMillis();
        if (millis < minSupportedDateMillis)
            throw new MarshalException(String.format("Input date %s is less than min supported date %s", source, new LocalDate(minSupportedDateMillis).toString()));
        if (millis > maxSupportedDateMillis)
            throw new MarshalException(String.format("Input date %s is greater than max supported date %s", source, new LocalDate(maxSupportedDateMillis).toString()));

        return timeInMillisToDay(millis);
    }
    catch (IllegalArgumentException e1)
    {
        throw new MarshalException(String.format("Unable to coerce '%s' to a formatted date (long)", source), e1);
    }
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:42,代碼來源:SimpleDateSerializer.java

示例14: convertToDatabaseValue

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public Long convertToDatabaseValue(DateTime entityProperty) {
    return entityProperty == null ? null : entityProperty.getMillis();
}
 
開發者ID:graviton57,項目名稱:TheNounProject,代碼行數:5,代碼來源:DateTimeConverter.java

示例15: verifyTransform

import org.joda.time.DateTime; //導入方法依賴的package包/類
private void verifyTransform(DateTime date) {
    Date expected = new Date(date.getMillis());
    assertThat(transformer.from(date), is(expected));
}
 
開發者ID:monPlan,項目名稱:springboot-spwa-gae-demo,代碼行數:5,代碼來源:DateTimeToDateTest.java


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