org.joda.time.ReadableDuration#getMillis ( )源码实例Demo

下面列出了org.joda.time.ReadableDuration#getMillis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: beam   文件: TimeUtil.java
/** Converts a {@link ReadableDuration} into a Dataflow API duration string. */
public static String toCloudDuration(ReadableDuration duration) {
  // Note that since Joda objects use millisecond resolution, we always
  // produce either no fractional seconds or fractional seconds with
  // millisecond resolution.
  long millis = duration.getMillis();
  long seconds = millis / 1000;
  millis = millis % 1000;
  if (millis == 0) {
    return String.format("%ds", seconds);
  } else {
    return String.format("%d.%03ds", seconds, millis);
  }
}
 
源代码2 项目: astor   文件: AbstractDuration.java
/**
 * Compares this duration with the specified duration based on length.
 *
 * @param other  a duration to check against
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws NullPointerException if the object is null
 * @throws ClassCastException if the given object is not supported
 */
public int compareTo(ReadableDuration other) {
    long thisMillis = this.getMillis();
    long otherMillis = other.getMillis();
    
    // cannot do (thisMillis - otherMillis) as it can overflow
    if (thisMillis < otherMillis) {
        return -1;
    }
    if (thisMillis > otherMillis) {
        return 1;
    }
    return 0;
}
 
源代码3 项目: astor   文件: AbstractDuration.java
/**
 * Compares this object with the specified object for equality based
 * on the millisecond length. All ReadableDuration instances are accepted.
 *
 * @param duration  a readable duration to check against
 * @return true if the length of the duration is equal
 */
public boolean equals(Object duration) {
    if (this == duration) {
        return true;
    }
    if (duration instanceof ReadableDuration == false) {
        return false;
    }
    ReadableDuration other = (ReadableDuration) duration;
    return (getMillis() == other.getMillis());
}
 
源代码4 项目: astor   文件: AbstractDuration.java
/**
 * Compares this duration with the specified duration based on length.
 *
 * @param other  a duration to check against
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws NullPointerException if the object is null
 * @throws ClassCastException if the given object is not supported
 */
public int compareTo(ReadableDuration other) {
    long thisMillis = this.getMillis();
    long otherMillis = other.getMillis();
    
    // cannot do (thisMillis - otherMillis) as it can overflow
    if (thisMillis < otherMillis) {
        return -1;
    }
    if (thisMillis > otherMillis) {
        return 1;
    }
    return 0;
}
 
源代码5 项目: astor   文件: AbstractDuration.java
/**
 * Compares this object with the specified object for equality based
 * on the millisecond length. All ReadableDuration instances are accepted.
 *
 * @param duration  a readable duration to check against
 * @return true if the length of the duration is equal
 */
public boolean equals(Object duration) {
    if (this == duration) {
        return true;
    }
    if (duration instanceof ReadableDuration == false) {
        return false;
    }
    ReadableDuration other = (ReadableDuration) duration;
    return (getMillis() == other.getMillis());
}
 
源代码6 项目: beam   文件: DurationCoder.java
private Long toLong(ReadableDuration value) {
  return value.getMillis();
}
 
源代码7 项目: astor   文件: ReadableDurationConverter.java
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritableDuration.
 *
 * @param writablePeriod  period to get modified
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use, must not be null
 * @throws NullPointerException if the duration or object is null
 * @throws ClassCastException if the object is an invalid type
 * @throws IllegalArgumentException if the object is invalid
 */
public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) {
    ReadableDuration dur = (ReadableDuration) object;
    chrono = DateTimeUtils.getChronology(chrono);
    long duration = dur.getMillis();
    int[] values = chrono.get(writablePeriod, duration);
    for (int i = 0; i < values.length; i++) {
        writablePeriod.setValue(i, values[i]);
    }
}
 
源代码8 项目: astor   文件: ReadableDurationConverter.java
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritableDuration.
 *
 * @param writablePeriod  period to get modified
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use, must not be null
 * @throws NullPointerException if the duration or object is null
 * @throws ClassCastException if the object is an invalid type
 * @throws IllegalArgumentException if the object is invalid
 */
public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) {
    ReadableDuration dur = (ReadableDuration) object;
    chrono = DateTimeUtils.getChronology(chrono);
    long duration = dur.getMillis();
    int[] values = chrono.get(writablePeriod, duration);
    for (int i = 0; i < values.length; i++) {
        writablePeriod.setValue(i, values[i]);
    }
}
 
 同类方法