Top Description Fields Constructors Methods
com.google.protobuf.util

public final Class TimeUtil

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
com.google.protobuf.Duration, .Timestamp, java.math.BigInteger, java.text.ParseException

Deprecated

Use Durations and Timestamps instead.

Utilities to help create/manipulate Timestamp/Duration

Field Summary

Modifier and TypeField and Description
public static final long
public static final long
private static final long
private static final BigInteger
public static final long
public static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Timestamp
add(Timestamp start, Duration length)

Deprecated Use Timestamps#add instead.
Add a duration to a timestamp.
public static Duration
add(Duration d1, Duration d2)

Deprecated Use Durations#add instead.
Add two durations.
private static Duration
public static Duration
createDurationFromMicros(long microseconds)

Deprecated Use Durations#fromMicros instead.
Create a Duration from the number of microseconds.
public static Duration
createDurationFromMillis(long milliseconds)

Deprecated Use Durations#fromMillis instead.
Create a Duration from the number of milliseconds.
public static Duration
createDurationFromNanos(long nanoseconds)

Deprecated Use Durations#fromNanos instead.
Create a Duration from the number of nanoseconds.
public static Timestamp
createTimestampFromMicros(long microseconds)

Deprecated Use Timestamps#fromMicros instead.
Create a Timestamp from the number of microseconds elapsed from the epoch.
public static Timestamp
createTimestampFromMillis(long milliseconds)

Deprecated Use Timestamps#fromMillis instead.
Create a Timestamp from the number of milliseconds elapsed from the epoch.
public static Timestamp
createTimestampFromNanos(long nanoseconds)

Deprecated Use Timestamps#fromNanos instead.
Create a Timestamp from the number of nanoseconds elapsed from the epoch.
public static Duration
distance(Timestamp from, Timestamp to)

Deprecated Use Timestamps#between instead.
Calculate the difference between two timestamps.
public static Duration
divide(Duration duration, double value)

public static Duration
divide(Duration duration, long times)

public static long
public static Timestamp
getCurrentTime()

Deprecated Use Timestamps.fromMillis(System.currentTimeMillis()) instead.
Get the current time.
public static Timestamp
getEpoch()

Deprecated Use Timestamps.fromMillis(0) instead.
Get the epoch.
public static Duration
multiply(Duration duration, double times)

public static Duration
multiply(Duration duration, long times)

private static Duration
normalizedDuration(long seconds, int nanos)

public static Duration

Returns:

A Duration parsed from the string.
parseDuration
(String value)

Deprecated Use Durations#parse instead.
Parse from a string to produce a duration.
public static Timestamp

Returns:

A Timestamp parsed from the string.
parseTimestamp
(String value)

Deprecated Use Timestamps#parse instead.
Parse from RFC 3339 date string to Timestamp.
public static Duration
public static Timestamp
subtract(Timestamp start, Duration length)

Deprecated Use Timestamps#subtract instead.
Subtract a duration from a timestamp.
public static Duration
subtract(Duration d1, Duration d2)

Deprecated Use Durations#subtract instead.
Subtract a duration from another.
private static BigInteger
private static BigInteger
toBigInteger(long value)

public static long
toMicros(Timestamp timestamp)

Deprecated Use Timestamps#toMicros instead.
Convert a Timestamp to the number of microseconds elapsed from the epoch.
public static long
toMicros(Duration duration)

Deprecated Use Durations#toMicros instead.
Convert a Duration to the number of microseconds.The result will be rounded towards 0 to the nearest microseconds.
public static long
toMillis(Timestamp timestamp)

Deprecated Use Timestamps#toMillis instead.
Convert a Timestamp to the number of milliseconds elapsed from the epoch.
public static long
toMillis(Duration duration)

Deprecated Use Durations#toMillis instead.
Convert a Duration to the number of milliseconds.The result will be rounded towards 0 to the nearest millisecond.
public static long
toNanos(Timestamp timestamp)

Deprecated Use Timestamps#toNanos instead.
Convert a Timestamp to the number of nanoseconds elapsed from the epoch.
public static long
toNanos(Duration duration)

Deprecated Use Durations#toNanos instead.
Convert a Duration to the number of nanoseconds.
public static String

Returns:

The string representation of the given timestamp.
toString
(Timestamp timestamp)

Deprecated Use Timestamps#toString instead.
Convert Timestamp to RFC 3339 date string format.
public static String

Returns:

The string representation of the given duration.
toString
(Duration duration)

Deprecated Use Durations#toString instead.
Convert Duration to string format.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DURATION_SECONDS_MAXback to summary
public static final long DURATION_SECONDS_MAX
DURATION_SECONDS_MINback to summary
public static final long DURATION_SECONDS_MIN
NANOS_PER_SECONDback to summary
private static final long NANOS_PER_SECOND
NANOS_PER_SECOND_BIG_INTEGERback to summary
private static final BigInteger NANOS_PER_SECOND_BIG_INTEGER
TIMESTAMP_SECONDS_MAXback to summary
public static final long TIMESTAMP_SECONDS_MAX
TIMESTAMP_SECONDS_MINback to summary
public static final long TIMESTAMP_SECONDS_MIN

Constructor Detail

TimeUtilback to summary
private TimeUtil()

Method Detail

addback to summary
public static Timestamp add(Timestamp start, Duration length)

Deprecated

Use Timestamps#add instead.

Add a duration to a timestamp.

Annotations
@Deprecated
addback to summary
public static Duration add(Duration d1, Duration d2)

Deprecated

Use Durations#add instead.

Add two durations.

Annotations
@Deprecated
createDurationFromBigIntegerback to summary
private static Duration createDurationFromBigInteger(BigInteger value)
createDurationFromMicrosback to summary
public static Duration createDurationFromMicros(long microseconds)

Deprecated

Use Durations#fromMicros instead.

Create a Duration from the number of microseconds.

Annotations
@Deprecated
createDurationFromMillisback to summary
public static Duration createDurationFromMillis(long milliseconds)

Deprecated

Use Durations#fromMillis instead.

Create a Duration from the number of milliseconds.

Annotations
@Deprecated
createDurationFromNanosback to summary
public static Duration createDurationFromNanos(long nanoseconds)

Deprecated

Use Durations#fromNanos instead.

Create a Duration from the number of nanoseconds.

Annotations
@Deprecated
createTimestampFromMicrosback to summary
public static Timestamp createTimestampFromMicros(long microseconds)

Deprecated

Use Timestamps#fromMicros instead.

Create a Timestamp from the number of microseconds elapsed from the epoch.

Annotations
@Deprecated
createTimestampFromMillisback to summary
public static Timestamp createTimestampFromMillis(long milliseconds)

Deprecated

Use Timestamps#fromMillis instead.

Create a Timestamp from the number of milliseconds elapsed from the epoch.

Annotations
@Deprecated
createTimestampFromNanosback to summary
public static Timestamp createTimestampFromNanos(long nanoseconds)

Deprecated

Use Timestamps#fromNanos instead.

Create a Timestamp from the number of nanoseconds elapsed from the epoch.

Annotations
@Deprecated
distanceback to summary
public static Duration distance(Timestamp from, Timestamp to)

Deprecated

Use Timestamps#between instead.

Calculate the difference between two timestamps.

Annotations
@Deprecated
divideback to summary
public static Duration divide(Duration duration, double value)
divideback to summary
public static Duration divide(Duration duration, long times)
divideback to summary
public static long divide(Duration d1, Duration d2)
getCurrentTimeback to summary
public static Timestamp getCurrentTime()

Deprecated

Use Timestamps.fromMillis(System.currentTimeMillis()) instead.

Get the current time.

Annotations
@Deprecated
getEpochback to summary
public static Timestamp getEpoch()

Deprecated

Use Timestamps.fromMillis(0) instead.

Get the epoch.

Annotations
@Deprecated
multiplyback to summary
public static Duration multiply(Duration duration, double times)
Annotations
@SuppressWarnings:DurationSecondsToDouble
multiplyback to summary
public static Duration multiply(Duration duration, long times)
normalizedDurationback to summary
private static Duration normalizedDuration(long seconds, int nanos)
parseDurationback to summary
public static Duration parseDuration(String value) throws ParseException

Deprecated

Use Durations#parse instead.

Parse from a string to produce a duration.

Returns:Duration

A Duration parsed from the string.

Annotations
@Deprecated
Exceptions
ParseException:
if parsing fails.
parseTimestampback to summary
public static Timestamp parseTimestamp(String value) throws ParseException

Deprecated

Use Timestamps#parse instead.

Parse from RFC 3339 date string to Timestamp. This method accepts all outputs of toString(Timestamp) and it also accepts any fractional digits (or none) and any offset as long as they fit into nano-seconds precision.

Example of accepted format: "1972-01-01T10:00:20.021-05:00"

Returns:Timestamp

A Timestamp parsed from the string.

Annotations
@Deprecated
Exceptions
ParseException:
if parsing fails.
remainderback to summary
public static Duration remainder(Duration d1, Duration d2)
subtractback to summary
public static Timestamp subtract(Timestamp start, Duration length)

Deprecated

Use Timestamps#subtract instead.

Subtract a duration from a timestamp.

Annotations
@Deprecated
subtractback to summary
public static Duration subtract(Duration d1, Duration d2)

Deprecated

Use Durations#subtract instead.

Subtract a duration from another.

Annotations
@Deprecated
toBigIntegerback to summary
private static BigInteger toBigInteger(Duration duration)
toBigIntegerback to summary
private static BigInteger toBigInteger(long value)
toMicrosback to summary
public static long toMicros(Timestamp timestamp)

Deprecated

Use Timestamps#toMicros instead.

Convert a Timestamp to the number of microseconds elapsed from the epoch.

The result will be rounded down to the nearest microsecond. E.g., if the timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.

Annotations
@Deprecated
toMicrosback to summary
public static long toMicros(Duration duration)

Deprecated

Use Durations#toMicros instead.

Convert a Duration to the number of microseconds.The result will be rounded towards 0 to the nearest microseconds. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Annotations
@Deprecated
toMillisback to summary
public static long toMillis(Timestamp timestamp)

Deprecated

Use Timestamps#toMillis instead.

Convert a Timestamp to the number of milliseconds elapsed from the epoch.

The result will be rounded down to the nearest millisecond. E.g., if the timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.

Annotations
@Deprecated
toMillisback to summary
public static long toMillis(Duration duration)

Deprecated

Use Durations#toMillis instead.

Convert a Duration to the number of milliseconds.The result will be rounded towards 0 to the nearest millisecond. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Annotations
@Deprecated
toNanosback to summary
public static long toNanos(Timestamp timestamp)

Deprecated

Use Timestamps#toNanos instead.

Convert a Timestamp to the number of nanoseconds elapsed from the epoch.

Annotations
@Deprecated
toNanosback to summary
public static long toNanos(Duration duration)

Deprecated

Use Durations#toNanos instead.

Convert a Duration to the number of nanoseconds.

Annotations
@Deprecated
toStringback to summary
public static String toString(Timestamp timestamp)

Deprecated

Use Timestamps#toString instead.

Convert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and uses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp can only represent time from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. See https://www.ietf.org/rfc/rfc3339.txt

Example of generated format: "1972-01-01T10:00:20.021Z"

Returns:String

The string representation of the given timestamp.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if the given timestamp is not in the valid range.
toStringback to summary
public static String toString(Duration duration)

Deprecated

Use Durations#toString instead.

Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits depending on the precision required to represent the exact Duration value. For example: "1s", "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from -315,576,000,000 to +315,576,000,000 inclusive (in seconds).

Returns:String

The string representation of the given duration.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if the given duration is not in the valid range.