TimeDifferenceComplicationText
public
final
class
TimeDifferenceComplicationText
extends Object
implements
TimeDependentText
| java.lang.Object | |
| ↳ | com.google.wear.services.complications.TimeDifferenceComplicationText |
Class to generate string representations of time differences.
Time differences greater than Integer.MAX_VALUE days are not supported.
Note: The preferred way to define dynamic data for complication text is to use a DynamicComplicationText. That will be the only supported way to create this type of ComplicationText in the future.
Summary
Nested classes | |
|---|---|
class |
TimeDifferenceComplicationText.Builder
Builder for |
Constants | |
|---|---|
int |
STYLE_SHORT_DUAL_UNIT
Style for time differences shown in a short alpha-numeric style, with up to two significant units included. |
int |
STYLE_SHORT_SINGLE_UNIT
Style for time differences shown in a short alpha-numeric style, with only the most significant unit included. |
int |
STYLE_SHORT_WORDS_SINGLE_UNIT
Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included, that should fit within the character limit for a short text field. |
int |
STYLE_STOPWATCH
Style for time differences shown in a numeric fashion like a timer. |
int |
STYLE_WORDS_SINGLE_UNIT
Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included. |
Public methods | |
|---|---|
boolean
|
equals(Object o)
|
TimeUnit
|
getMinimumUnit()
Returns the minimum |
long
|
getNextChangeTimeMillis(long fromTime)
Returns the next time after |
long
|
getPrecisionMillis()
Returns the time precision in milliseconds. |
long
|
getReferencePeriodEndMillis()
Returns the end of the reference period, as milliseconds since epoch. |
long
|
getReferencePeriodStartMillis()
Returns the start of the reference period, as milliseconds since epoch. |
int
|
getStyle()
Returns the time difference style to be used when formatting the text. |
CharSequence
|
getSurroundingText()
|
int
|
hashCode()
|
boolean
|
isShowNowText()
Returns true if text for "now" should be shown when within the reference period. |
boolean
|
returnsSameTextAt(long firstDateTimeMillis, long secondDateTimeMillis)
Returns true if the result of the calculation of the current text will be the same for both
|
String
|
toString()
|
Inherited methods | |
|---|---|
Constants
STYLE_SHORT_DUAL_UNIT
public static final int STYLE_SHORT_DUAL_UNIT
Style for time differences shown in a short alpha-numeric style, with up to two significant units included.
For time difference t:
If t < 1 hour, the value will be shown as a number of minutes, such as 2m
for 2 minutes. Seconds are not displayed.
If 1 hour <= t < 1 day, the value will be shown as hours and minutes, such as
4h 2m for 4 hours and 2 minutes.
If 1 day <= t < 10 days, the value will be shown as days and hours, such as 3d 4h for 3 days 4 hours.
If 10 days <= t, the value will be shown as a number of days, such as 13d
for 13 days.
The characters used will be localised to match the default locale. If the representation of the time difference with two units would be too long in the default locale, just a single unit may be shown instead.
Constant Value: 3 (0x00000003)
STYLE_SHORT_SINGLE_UNIT
public static final int STYLE_SHORT_SINGLE_UNIT
Style for time differences shown in a short alpha-numeric style, with only the most significant unit included.
For time difference t:
If t < 1 hour, the value will be shown as a number of minutes, such as 2m
for 2 minutes. Seconds are not displayed.
If 1 hour <= t < 1 day, the value will be shown as a number of hours, such as
4h for 4 hours.
If 1 days <= t, the value will be shown as a number of days, such as 13d
for 13 days.
The characters used will be localised to match the default locale.
Constant Value: 2 (0x00000002)
STYLE_SHORT_WORDS_SINGLE_UNIT
public static final int STYLE_SHORT_WORDS_SINGLE_UNIT
Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included, that should fit within the character limit for a short text field.
The output will be the same as for STYLE_WORDS_SINGLE_UNIT, except that if the
text does not fit into the seven character limit then a shorter form will be used instead,
e.g. "1356d" instead of "1356 days".
Constant Value: 5 (0x00000005)
STYLE_STOPWATCH
public static final int STYLE_STOPWATCH
Style for time differences shown in a numeric fashion like a timer.
For time difference t:
If t < 1 hour, the value will be shown as minutes and seconds, such as 02:35 for 2 minutes and 35 seconds.
If 1 hour <= t < 1 day, the value will be shown as hours and minutes, such as
4:02 for 4 hours and 2 minutes, or as 12:02 for 12 hours and 2 minutes.
If 1 day <= t < 10 days, the value will be shown as days and hours, such as 3d 4h for 3 days 4 hours.
If 10 days <= t, the value will be shown as just days, such as 13d for 13
days.
The characters used will be localised to match the default locale.
Constant Value: 1 (0x00000001)
STYLE_WORDS_SINGLE_UNIT
public static final int STYLE_WORDS_SINGLE_UNIT
Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included.
For time difference t:
If t < 1 hour, the value will be shown as a number of minutes, such as 1
min for 1 minute or 2 mins for 2 minutes. Seconds are not displayed.
If 1 hour <= t < 1 day, the value will be shown as a number of hours, such as
1 hour for 1 hour or 4 hours for 4 hours.
If 1 days <= t, the value will be shown as a number of days, such as 1 day
for 1 day or 13 days for 13 days.
The words used will be localised to match the default locale.
Constant Value: 4 (0x00000004)
Public methods
getMinimumUnit
public TimeUnit getMinimumUnit ()
Returns the minimum TimeUnit specified, or null if none has been specified.
| Returns | |
|---|---|
TimeUnit |
|
getNextChangeTimeMillis
public long getNextChangeTimeMillis (long fromTime)
Returns the next time after fromTime at which the text may change.
| Parameters | |
|---|---|
fromTime |
long |
| Returns | |
|---|---|
long |
|
getPrecisionMillis
public long getPrecisionMillis ()
Returns the time precision in milliseconds.
The result is max(getMinimumUnit(), 1000) for STYLE_STOPWATCH or 1000
otherwise.
| Returns | |
|---|---|
long |
|
getReferencePeriodEndMillis
public long getReferencePeriodEndMillis ()
Returns the end of the reference period, as milliseconds since epoch.
| Returns | |
|---|---|
long |
|
getReferencePeriodStartMillis
public long getReferencePeriodStartMillis ()
Returns the start of the reference period, as milliseconds since epoch.
| Returns | |
|---|---|
long |
|
getStyle
public int getStyle ()
Returns the time difference style to be used when formatting the text.
| Returns | |
|---|---|
int |
Value is one of the following: |
getSurroundingText
public CharSequence getSurroundingText ()
| Returns | |
|---|---|
CharSequence |
|
isShowNowText
public boolean isShowNowText ()
Returns true if text for "now" should be shown when within the reference period.
| Returns | |
|---|---|
boolean |
|
returnsSameTextAt
public boolean returnsSameTextAt (long firstDateTimeMillis,
long secondDateTimeMillis)Returns true if the result of the calculation of the current text will be the same for both
firstDateTimeMillis and secondDateTimeMillis.
| Parameters | |
|---|---|
firstDateTimeMillis |
long |
secondDateTimeMillis |
long |
| Returns | |
|---|---|
boolean |
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-06-11 UTC.