Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 2.17 KB

date_time.rst

File metadata and controls

48 lines (33 loc) · 2.17 KB

Date-Time

The date-time library maintains the current date-time information in UTC format. The option :option:`CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS` determines the frequency with which the library updates the date-time information.

The information is fetched in the following prioritized order:

  1. The library checks if the current date-time information is valid and relatively new. If the date-time information currently set in the library was obtained sometime during the interval set by CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS, the library does not fetch new date-time information. In this way, unnecessary update cycles are avoided.
  2. If the aforementioned check fails, the library requests time from the onboard modem of nRF9160.
  3. If the time information obtained from the onboard modem of nRF9160 is not valid, the library requests time from NTP servers.
  4. If the NTP time request does not succeed, the library tries to request time information from several other NTP servers, before it fails.

The :c:func:`date_time_set` function can be used to obtain the current date-time information from external sources independent of the internal date-time update routine. Time from GPS can be such an external source.

To get date-time information from the library, either call the :c:func:`date_time_uptime_to_unix_time_ms` function or the :c:func:`date_time_now` function. See the API documentation for more information on these functions.

Note

The first date-time update cycle (after boot) does not occur until the time set by the :option:`CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS` has elapsed. It is recommended to call the :c:func:`date_time_update_async` function after the device has connected to LTE, to get the initial date-time information.

:option:`CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS`

Configure this option to control the frequency with which the library fetches the time information.
.. doxygengroup:: date_time
   :project: nrf
   :members: