下面列出了org.joda.time.ReadableDuration#getMillis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** 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);
}
}
/**
* 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;
}
/**
* 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());
}
/**
* 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;
}
/**
* 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());
}
private Long toLong(ReadableDuration value) {
return value.getMillis();
}
/**
* 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]);
}
}
/**
* 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]);
}
}