# TimeManager

Summary:[Constants](https://developer.android.com/reference/com/google/android/things/device/TimeManager#constants)\|[Methods](https://developer.android.com/reference/com/google/android/things/device/TimeManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/things/device/TimeManager#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/com/google/android/things/device/TimeManager#)  

# TimeManager

`
public


class
TimeManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|----------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | com.google.android.things.device.TimeManager |

<br />

*** ** * ** ***

This class provides access to device settings related to time. This includes the following operations:

- Time format (12-hour or 24-hour)
- Time zone
- Auto sync time from a Network Time Protocol (NTP) server

To control device settings using`TimeManager`, first request the permission`com.google.android.things.permission.SET_TIME`in your`AndroidManifest.xml`, then obtain an instance of the class and set the properties appropriate for your app.  

     TimeManager timeManager = TimeManager.getInstance();
     // Use 24-hour time
     timeManager.setTimeFormat(TimeManager.FORMAT_24);

     // Set time zone to Eastern Standard Time
     timeManager.setTimeZone("America/New_York");

     // Set clock time to noon
     Calendar calendar = Calendar.getInstance();
     calendar.set(Calendar.MILLISECOND, 0);
     calendar.set(Calendar.SECOND, 0);
     calendar.set(Calendar.MINUTE, 0);
     calendar.set(Calendar.HOUR_OF_DAY, 12);
     long timeStamp = calendar.getTimeInMillis();
     timeManager.setTime(timeStamp);

To get the current time or time zone, obtain a[Calendar](https://developer.android.com/reference/java/util/Calendar.html)instance:  

     Calendar calendar = Calendar.getInstance();
     long now = calendar.getTimeInMillis();
     TimeZone current = calendar.getTimeZone();

Current values for other time-related settings can be read from[Settings.Global](https://developer.android.com/reference/android/provider/Settings.Global.html).

## Summary

|                                                             ### Constants                                                              ||
|-------|---------------------------------------------------------------------------------------------------------------------------------|
| `int` | [FORMAT_12](https://developer.android.com/reference/com/google/android/things/device/TimeManager#FORMAT_12) 12 hour time format |
| `int` | [FORMAT_24](https://developer.android.com/reference/com/google/android/things/device/TimeManager#FORMAT_24) 24 hour time format |

|                                                                                                                                                                                  ### Public methods                                                                                                                                                                                   ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[TimeManager](https://developer.android.com/reference/com/google/android/things/device/TimeManager) | ` `[getInstance](https://developer.android.com/reference/com/google/android/things/device/TimeManager#getInstance())`() ` Returns the[TimeManager](https://developer.android.com/reference/com/google/android/things/device/TimeManager)instance for this application. |
| ` void`                                                                                                       | ` `[setAutoTimeEnabled](https://developer.android.com/reference/com/google/android/things/device/TimeManager#setAutoTimeEnabled(boolean))`(boolean enabled) ` Sets whether or not wall clock time should sync with automatic time updates from NTP.                    |
| ` void`                                                                                                       | ` `[setTime](https://developer.android.com/reference/com/google/android/things/device/TimeManager#setTime(long))`(long millis) ` Set the system wall clock time.                                                                                                       |
| ` void`                                                                                                       | ` `[setTimeFormat](https://developer.android.com/reference/com/google/android/things/device/TimeManager#setTimeFormat(int))`(int timeFormat) ` Sets the time format for the device.                                                                                    |
| ` void`                                                                                                       | ` `[setTimeZone](https://developer.android.com/reference/com/google/android/things/device/TimeManager#setTimeZone(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` timeZone) ` Set the system's persistent default time zone.  |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/device/TimeManager#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                                                                                                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                                                                                                                                                                                                                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                                                                                                                                                                                                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                                                                                                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                                                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long, int))`(long millis, int nanos) ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long millis) ` Causes the current thread to wait until either another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object, or a specified amount of time has elapsed.                                                                 | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object.                                                                                                                                  | ||

## Constants

### FORMAT_12

```
int FORMAT_12
```

12 hour time format

<br />

Constant Value: 12 (0x0000000c)  

### FORMAT_24

```
int FORMAT_24
```

24 hour time format

<br />

Constant Value: 24 (0x00000018)

## Public methods

### getInstance

```
TimeManager getInstance ()
```

Returns the[TimeManager](https://developer.android.com/reference/com/google/android/things/device/TimeManager)instance for this application.

<br />

|                                                                Returns                                                                ||
|-----------------------------------------------------------------------------------------------------|----------------------------------|
| [TimeManager](https://developer.android.com/reference/com/google/android/things/device/TimeManager) | The TimeManager instance. <br /> |

### setAutoTimeEnabled

```
void setAutoTimeEnabled (boolean enabled)
```

Sets whether or not wall clock time should sync with automatic time updates from NTP.

<br />

|                                Parameters                                 ||
|-----------|----------------------------------------------------------------|
| `enabled` | `boolean`: if true, automatic time updates are enabled. <br /> |

|                                                                                             Throws                                                                                              ||
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the underlying system service is not ready                                                 |
| [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException)           | if the underlying system service encountered an error                                         |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)         | if the calling context does not have com.google.android.things.permission.SET_TIME permission |

### setTime

```
void setTime (long millis)
```

Set the system wall clock time. This method does not guarantee persistence past reboot. This method also disables automatic time updates from NTP.

<br />

|                             Parameters                             ||
|----------|----------------------------------------------------------|
| `millis` | `long`: time in milliseconds since the Unix Epoch <br /> |

|                                                                                             Throws                                                                                              ||
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the underlying system service is not ready                                                 |
| [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException)           | if the underlying system service encountered an error                                         |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)         | if the calling context does not have com.google.android.things.permission.SET_TIME permission |

### setTimeFormat

```
void setTimeFormat (int timeFormat)
```

Sets the time format for the device. This should be either FORMAT_12 or FORMAT_24.

<br />

|                      Parameters                      ||
|--------------|----------------------------------------|
| `timeFormat` | `int`: the timeFormat to be set <br /> |

|                                                                                             Throws                                                                                              ||
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the underlying system service is not ready                                                 |
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException.html)       | if the underlying system service encountered an error                                         |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)         | if the calling context does not have com.google.android.things.permission.SET_TIME permission |

### setTimeZone

```
void setTimeZone (String timeZone)
```

Set the system's persistent default time zone. This sets the time zone for all apps, even after reboot.

<br />

|                                               Parameters                                               ||
|------------|--------------------------------------------------------------------------------------------|
| `timeZone` | `String`: one of the Olson ids from the list returned by TimeZone.getAvailableIDs() <br /> |

|                                                                                             Throws                                                                                              ||
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the underlying system service is not ready                                                 |
| [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException)           | if the underlying system service encountered an error                                         |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)         | if the calling context does not have com.google.android.things.permission.SET_TIME permission |

-

  ## Classes

  - [DeviceManager](https://developer.android.com/reference/com/google/android/things/device/DeviceManager)
  - [TimeManager](https://developer.android.com/reference/com/google/android/things/device/TimeManager)