<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf9160: How to make time() return correct time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55312/nrf9160-how-to-make-time-return-correct-time</link><description>Hi, 
 What is the proper way to set &amp;quot;real time&amp;quot; in nRF9160 with nRF Connect SDK? 
 I want the function time() from the file time.h to return the correct time. 
 I know that I can read the correct time from the modem with +CCLK when connected to the network</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 Dec 2019 14:34:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55312/nrf9160-how-to-make-time-return-correct-time" /><item><title>RE: nrf9160: How to make time() return correct time?</title><link>https://devzone.nordicsemi.com/thread/224229?ContentTypeID=1</link><pubDate>Fri, 06 Dec 2019 14:34:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c36c690-8555-4257-8936-c3d2a09418c8</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Björn,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]But how do I &amp;quot;plug&amp;quot; the correct time into the system so time() works as expected?[/quote]
&lt;p&gt;I think you have to write your own time() function to be able to do this, if you require the use of time() specifically.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]What is the proper way to set &amp;quot;real time&amp;quot; in nRF9160 with nRF Connect SDK?[/quote]
&lt;p&gt;There&amp;#39;s many ways of setting or fetching time. One is the +CCLK, as you mention, another is the GPS, and you could also do this over NTP as well.&lt;/p&gt;
&lt;p&gt;Setting it on the logger seems to be possible using &amp;quot;&lt;span&gt;log_set_timestamp_func()&amp;quot;:&amp;nbsp;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/master/include/logging/log_ctrl.h#L66"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/master/include/logging/log_ctrl.h#L66&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However; a generic time module isn&amp;#39;t available as far as I know.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Håkon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>