org.joda.time.Instant.getMillis()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中org.joda.time.Instant.getMillis()方法的一些代码示例,展示了Instant.getMillis()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instant.getMillis()方法的具体详情如下:
包路径:org.joda.time.Instant
类名称:Instant
方法名:getMillis

Instant.getMillis介绍

[英]Gets the milliseconds of the instant.
[中]获取瞬间的毫秒数。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

public static Time closest(Time ref, Time... times) {
 Time res = null;
 long refMillis = ref.getJodaTimeInstant().getMillis();
 long min = 0;
 for (Time t:times) {
  long d = Math.abs(refMillis - t.getJodaTimeInstant().getMillis());
  if (res == null || d < min) {
   res = t;
   min = d;
  }
 }
 return res;
}

代码示例来源:origin: spotify/helios

private long totalRunningTimeMillis() {
 int duration = 0;
 for (final Long exit : exits) {
  duration += exit;
 }
 if (running) {
  duration += clock.now().getMillis() - startMillis;
 }
 return duration;
}

代码示例来源:origin: spotify/helios

public synchronized void exited() {
 running = false;
 exits.add(clock.now().getMillis() - startMillis);
 while (exits.size() > restartCount) {
  exits.pop();
 }
}

代码示例来源:origin: joda-time/joda-time

/**
 * Get this object as a DateTime using ISOChronology in the default zone.
 * <p>
 * This method returns a DateTime object in the default zone.
 * This differs from the similarly named method on DateTime, DateMidnight
 * or MutableDateTime which retains the time zone. The difference is
 * because Instant really represents a time <i>without</i> a zone,
 * thus calling this method we really have no zone to 'retain' and
 * hence expect to switch to the default zone.
 * <p>
 * This method definition preserves compatibility with earlier versions
 * of Joda-Time.
 *
 * @return a DateTime using the same millis
 */
public DateTime toDateTime() {
  return new DateTime(getMillis(), ISOChronology.getInstance());
}

代码示例来源:origin: spotify/helios

public synchronized void started() {
 running = true;
 startMillis = clock.now().getMillis();
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Get this object as a DateTime using ISOChronology in the default zone.
 * <p>
 * This method returns a DateTime object in the default zone.
 * This differs from the similarly named method on DateTime, DateMidnight
 * or MutableDateTime which retains the time zone. The difference is
 * because Instant really represents a time <i>without</i> a zone,
 * thus calling this method we really have no zone to 'retain' and
 * hence expect to switch to the default zone.
 * <p>
 * This method definition preserves compatibility with earlier versions
 * of Joda-Time.
 *
 * @return a DateTime using the same millis
 */
public DateTime toDateTime() {
  return new DateTime(getMillis(), ISOChronology.getInstance());
}

代码示例来源:origin: joda-time/joda-time

/**
 * Get this object as a MutableDateTime using ISOChronology in the default zone.
 * <p>
 * This method returns a MutableDateTime object in the default zone.
 * This differs from the similarly named method on DateTime, DateMidnight
 * or MutableDateTime which retains the time zone. The difference is
 * because Instant really represents a time <i>without</i> a zone,
 * thus calling this method we really have no zone to 'retain' and
 * hence expect to switch to the default zone.
 * <p>
 * This method definition preserves compatibility with earlier versions
 * of Joda-Time.
 *
 * @return a MutableDateTime using the same millis
 */
public MutableDateTime toMutableDateTime() {
  return new MutableDateTime(getMillis(), ISOChronology.getInstance());
}

代码示例来源:origin: spotify/helios

@Override
public ListenableFuture<Response> request(final URI uri,
                     final String method,
                     final byte[] entityBytes,
                     final Map<String, List<String>> headers) {
 final long deadline = clock.now().getMillis() + retryTimeoutMillis;
 final SettableFuture<Response> future = SettableFuture.create();
 final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() {
  @Override
  public ListenableFuture<Response> get() {
   return delegate.request(uri, method, entityBytes, headers);
  }
 };
 startRetry(future, code, deadline, delayMillis, uri);
 return future;
}

代码示例来源:origin: joda-time/joda-time

/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static GJChronology getInstance(
    DateTimeZone zone,
    long gregorianCutover,
    int minDaysInFirstWeek) {
  
  Instant cutoverInstant;
  if (gregorianCutover == DEFAULT_CUTOVER.getMillis()) {
    cutoverInstant = null;
  } else {
    cutoverInstant = new Instant(gregorianCutover);
  }
  return getInstance(zone, cutoverInstant, minDaysInFirstWeek);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Get this object as a MutableDateTime using ISOChronology in the default zone.
 * <p>
 * This method returns a MutableDateTime object in the default zone.
 * This differs from the similarly named method on DateTime, DateMidnight
 * or MutableDateTime which retains the time zone. The difference is
 * because Instant really represents a time <i>without</i> a zone,
 * thus calling this method we really have no zone to 'retain' and
 * hence expect to switch to the default zone.
 * <p>
 * This method definition preserves compatibility with earlier versions
 * of Joda-Time.
 *
 * @return a MutableDateTime using the same millis
 */
public MutableDateTime toMutableDateTime() {
  return new MutableDateTime(getMillis(), ISOChronology.getInstance());
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static GJChronology getInstance(
    DateTimeZone zone,
    long gregorianCutover,
    int minDaysInFirstWeek) {
  
  Instant cutoverInstant;
  if (gregorianCutover == DEFAULT_CUTOVER.getMillis()) {
    cutoverInstant = null;
  } else {
    cutoverInstant = new Instant(gregorianCutover);
  }
  return getInstance(zone, cutoverInstant, minDaysInFirstWeek);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Gets a copy of this instant with the specified duration added.
 * <p>
 * If the addition is zero, then <code>this</code> is returned.
 * 
 * @param durationToAdd  the duration to add to this one
 * @param scalar  the amount of times to add, such as -1 to subtract once
 * @return a copy of this instant with the duration added
 * @throws ArithmeticException if the new instant exceeds the capacity of a long
 */
public Instant withDurationAdded(long durationToAdd, int scalar) {
  if (durationToAdd == 0 || scalar == 0) {
    return this;
  }
  long instant = getChronology().add(getMillis(), durationToAdd, scalar);
  return withMillis(instant);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static void updateTimeZoneNames(Locale locale) {
   long time1 = new SUTime.IsoDate(2013,1,1).getJodaTimeInstant().getMillis();
   long time2 = new SUTime.IsoDate(2013,6,1).getJodaTimeInstant().getMillis();
   CollectionValuedMap<String,DateTimeZone> tzMap = new CollectionValuedMap<>();
   for (DateTimeZone dtz:TimeZoneIdComponent.timeZonesById.values()) {
    // standard timezones
    tzMap.add(dtz.getShortName(time1, locale).toLowerCase(), dtz);
    tzMap.add(dtz.getName(time1, locale).toLowerCase(), dtz);
    // Add about half a year to get day light savings timezones...
    tzMap.add(dtz.getShortName(time2, locale).toLowerCase(), dtz);
    tzMap.add(dtz.getName(time2, locale).toLowerCase(), dtz);
//      tzMap.add(dtz.getNameKey(time).toLowerCase(), dtz);
//      tzMap.add(dtz.getID().toLowerCase(), dtz);
   }
   // Order by length for regex
   List<String> tzNames = new ArrayList<>(tzMap.keySet());
   Collections.sort(tzNames, STRING_LENGTH_REV_COMPARATOR);
   String tzRegex = makeRegex(tzNames);
   synchronized (TimeZoneComponent.class) {
    timeZoneNames.put(locale,tzNames);
    timeZonesByName.put(locale,tzMap);
    timeZoneRegexes.put(locale,tzRegex);
   }
  }

代码示例来源:origin: JodaOrg/joda-time

/**
 * Gets a copy of this instant with the specified duration added.
 * <p>
 * If the addition is zero, then <code>this</code> is returned.
 * 
 * @param durationToAdd  the duration to add to this one
 * @param scalar  the amount of times to add, such as -1 to subtract once
 * @return a copy of this instant with the duration added
 * @throws ArithmeticException if the new instant exceeds the capacity of a long
 */
public Instant withDurationAdded(long durationToAdd, int scalar) {
  if (durationToAdd == 0 || scalar == 0) {
    return this;
  }
  long instant = getChronology().add(getMillis(), durationToAdd, scalar);
  return withMillis(instant);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
  StringBuffer sb = new StringBuffer(60);
  sb.append("GJChronology");
  sb.append('[');
  sb.append(getZone().getID());
  
  if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
    sb.append(",cutover=");
    DateTimeFormatter printer;
    if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
      printer = ISODateTimeFormat.date();
    } else {
      printer = ISODateTimeFormat.dateTime();
    }
    printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
  }
  
  if (getMinimumDaysInFirstWeek() != 4) {
    sb.append(",mdfw=");
    sb.append(getMinimumDaysInFirstWeek());
  }
  sb.append(']');
  
  return sb.toString();
}

代码示例来源:origin: spotify/helios

@SuppressWarnings("CheckReturnValue")
private void handleFailure(final SettableFuture<Response> future,
              final Supplier<ListenableFuture<Response>> code,
              final long deadline,
              final long delayMillis,
              final Throwable th,
              final URI uri) {
 if (clock.now().getMillis() < deadline) {
  if (delayMillis > 0) {
   executorService.schedule(new Runnable() {
    @Override
    public void run() {
     startRetry(future, code, deadline - 1, delayMillis, uri);
    }
   }, delayMillis, TimeUnit.MILLISECONDS);
  } else {
   startRetry(future, code, deadline - 1, delayMillis, uri);
  }
 } else {
  future.setException(th);
 }
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
  StringBuffer sb = new StringBuffer(60);
  sb.append("GJChronology");
  sb.append('[');
  sb.append(getZone().getID());
  
  if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
    sb.append(",cutover=");
    DateTimeFormatter printer;
    if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
      printer = ISODateTimeFormat.date();
    } else {
      printer = ISODateTimeFormat.dateTime();
    }
    printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
  }
  
  if (getMinimumDaysInFirstWeek() != 4) {
    sb.append(",mdfw=");
    sb.append(getMinimumDaysInFirstWeek());
  }
  sb.append(']');
  
  return sb.toString();
}

代码示例来源:origin: joda-time/joda-time

} else {
  cutoverInstant = gregorianCutover.toInstant();
  LocalDate cutoverDate = new LocalDate(cutoverInstant.getMillis(), GregorianChronology.getInstance(zone));
  if (cutoverDate.getYear() <= 0) {
    throw new IllegalArgumentException("Cutover too early. Must be on or after 0001-01-01.");

代码示例来源:origin: alibaba/fastjson

out.writeLong(dateTime.toDateTime(DateTimeZone.forTimeZone(JSON.defaultTimeZone)).toInstant().getMillis());

代码示例来源:origin: stanfordnlp/CoreNLP

public static Duration difference(Time t1, Time t2) {
 // TODO: Difference does not work between days of the week
 // Get duration from this t1 to t2
 if (t1 == null || t2 == null)
  return null;
 Instant i1 = t1.getJodaTimeInstant();
 Instant i2 = t2.getJodaTimeInstant();
 if (i1 == null || i2 == null)
  return null;
 Duration d = new DurationWithMillis(i2.getMillis() - i1.getMillis());
 Duration g1 = t1.getGranularity();
 Duration g2 = t2.getGranularity();
 Duration g = Duration.max(g1, g2);
 if (g != null) {
  Period p = g.getJodaTimePeriod();
  p = p.normalizedStandard();
  Period p2 = JodaTimeUtils.discardMoreSpecificFields(d.getJodaTimePeriod(), p.getFieldType(p.size() - 1), i1.getChronology());
  return new DurationWithFields(p2);
 } else {
  return d;
 }
}

相关文章