Added in API level 17

TextClock


open class TextClock : TextView
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.TextClock

TextClock can display the current date and/or time as a formatted string.

This view honors the 24-hour format system setting. As such, it is possible and recommended to provide two different formatting patterns: one to display the date/time in 24-hour mode and one to display the date/time in 12-hour mode. Most callers will want to use the defaults, though, which will be appropriate for the user's locale.

It is possible to determine whether the system is currently in 24-hour mode by calling is24HourModeEnabled().

The rules used by this widget to decide how to format the date and time are the following:

  • In 24-hour mode:
    • Use the value returned by getFormat24Hour() when non-null
    • Otherwise, use the value returned by getFormat12Hour() when non-null
    • Otherwise, use a default value appropriate for the user's locale, such as h:mm a
  • In 12-hour mode:
    • Use the value returned by getFormat12Hour() when non-null
    • Otherwise, use the value returned by getFormat24Hour() when non-null
    • Otherwise, use a default value appropriate for the user's locale, such as HH:mm

The CharSequence instances used as formatting patterns when calling either setFormat24Hour(java.lang.CharSequence) or setFormat12Hour(java.lang.CharSequence) can contain styling information. To do so, use a android.text.Spanned object. Note that if you customize these strings, it is your responsibility to supply strings appropriate for formatting dates and/or times in the user's locale.

Summary

XML attributes
android:format12Hour Specifies the formatting pattern used to show the time and/or date in 12-hour mode.
android:format24Hour Specifies the formatting pattern used to show the time and/or date in 24-hour mode.
android:timeZone Specifies the time zone to use.
Inherited XML attributes
Inherited constants
Public constructors
TextClock(context: Context!)

Creates a new clock using the default patterns for the current locale.

TextClock(context: Context!, attrs: AttributeSet!)

Creates a new clock inflated from XML.

TextClock(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Creates a new clock inflated from XML.

TextClock(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open CharSequence!

Returns the formatting pattern used to display the date and/or time in 12-hour mode.

open CharSequence!

Returns the formatting pattern used to display the date and/or time in 24-hour mode.

open String!

Indicates which time zone is currently used by this view.

open Boolean

Indicates whether the system is currently using the 24-hour mode.

open Unit

open Unit

Update the displayed time if necessary and invalidate the view.

open Unit

Specifies the formatting pattern used to display the date and/or time in 12-hour mode.

open Unit

Specifies the formatting pattern used to display the date and/or time in 24-hour mode.

open Unit
setTimeZone(timeZone: String!)

Sets the specified time zone to use in this clock.

Protected methods
open Unit

open Unit

Inherited functions