<?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>How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/32021/how-to-convert-date-and-time-to-timestamp</link><description>Hi, I use IoT sdk with my iPhone to get current date and time, date comes in ble_cts_c_evt_t structure, how can I convert it to timestamp, I know that I have to subscribe Jan 1, 1970 from current date and multiple all by 84600, but maybe is there more</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Mar 2018 13:20:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/32021/how-to-convert-date-and-time-to-timestamp" /><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/125171?ContentTypeID=1</link><pubDate>Tue, 20 Mar 2018 13:20:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12e1495d-e9eb-4cc1-af66-e9d931b6a101</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;Did you check that the month in ble_date_time_t&amp;nbsp;is returned as a value from 0 to 11 (not 1-12)?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct tm {
    ...
    int tm_mon;   /* months since January, 0 to 11 */
    ...
};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/125044?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 15:40:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2934d38b-6e40-47d9-a1de-43a67e55aa11</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;yes, always 1 month forward, I subtract 1 month from current month to get correct value, but it&amp;#39;s not right solution, I guess&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/125041?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 15:35:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1978f984-a852-4443-a475-f11689d689cc</guid><dc:creator>Bj&amp;#248;rn Kvaale</dc:creator><description>&lt;p&gt;Is the time always one month forward? If so, it seems like there is some kind of offset that leads to an incorrect date.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/124910?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 07:57:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a0fb296-c90e-4dd8-8db7-91484ee9fc27</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;My app based on this current time application, and I got the correct date and time, but when I put it in tm structure and called mktime, I got wrong value of timestamp. Usually one month forward, i.e. if today is 19.03.2018 10:56:34, then my timestamp (after converting back in online service) shows 19.04.2018 10:56:34 (or UTC0 7:56:34)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/124344?ContentTypeID=1</link><pubDate>Wed, 14 Mar 2018 10:36:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce7c986-34ae-4dfb-998c-aadf1cf763ed</guid><dc:creator>Bj&amp;#248;rn Kvaale</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/12312/how-can-i-get-time-stamp-from-rtc1-timer-while-i-am-using-app_timer-softdevice" target="_blank" rel="noopener noreferrer"&gt;This devzone case&lt;/a&gt; might be helpful. In addition, the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/ble_sdk_app_cts_c.html?cp=4_0_0_4_2_2_7" target="_blank" rel="noopener noreferrer"&gt;current time application&lt;/a&gt; in the nrf sdk could be helpful. See the current_time_print() function in the main.c file for more info. The current_time_print() function also takes in a&amp;nbsp;ble_cts_c_evt_t struct &amp;amp; converts the data to hours, minutes, seconds &amp;amp; fractions of a second.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/124142?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 11:18:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f170175f-8a4b-43ea-8479-9c24fb31c710</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;If I use mktime, I get incorrect data&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct tm time_struct;
ble_date_time_t datetime = p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time;
time_t newtime;
time_struct.tm_year = datetime.year - 1900;
time_struct.tm_mon = datetime.month;
time_struct.tm_mday = datetime.day;
time_struct.tm_hour = datetime.hours;
time_struct.tm_min = datetime.minutes;
time_struct.tm_sec = datetime.seconds;
newtime = mktime(&amp;amp;time_struct);

NRF_LOG_INFO(&amp;quot;Timestamp is %ld\r\n&amp;quot;, newtime); // got tomorrow day

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert date and time to timestamp?</title><link>https://devzone.nordicsemi.com/thread/124101?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 09:22:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85ad69a6-7678-4434-88e4-21e52020ece6</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;You could use the mktime() function from the ANSI C library. See this &lt;a href="http://en.cppreference.com/w/cpp/chrono/c/mktime"&gt;example&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>