1.. zephyr:code-sample:: posix-gettimeofday 2 :name: gettimeofday() with clock initialization 3 4 Use ``gettimeofday()`` with clock initialization over SNTP. 5 6Overview 7******** 8 9This sample application demonstrates using the POSIX `gettimeofday()`_ function to display the 10absolute wall clock time and local time every second. At system startup, the current time is 11queried using the SNTP networking protocol, enabled by setting the 12:kconfig:option:`CONFIG_NET_CONFIG_CLOCK_SNTP_INIT` and 13:kconfig:option:`CONFIG_NET_CONFIG_SNTP_INIT_SERVER` options. 14 15Requirements 16************ 17 18- :ref:`networking_with_host` 19- or, a board with hardware networking 20- NAT/routing should be set up to allow connections to the Internet 21- DNS server should be available on the host to resolve domain names 22 23Building and Running 24******************** 25 26This project outputs to the console. It can be built and executed on QEMU as follows: 27 28.. zephyr-app-commands:: 29 :zephyr-app: samples/posix/gettimeofday 30 :host-os: unix 31 :board: qemu_x86 32 :goals: run 33 :compact: 34 35For comparison, to build directly for your host OS if it is POSIX compliant (for ex. Linux): 36 37.. code-block:: console 38 39 cd samples/posix/gettimeofday 40 make -f Makefile.host 41 42The make output file will be located in samples/posix/gettimeofday/build. 43 44.. _gettimeofday(): https://pubs.opengroup.org/onlinepubs/009604599/functions/gettimeofday.html 45