{"id":1394,"date":"2023-08-24T13:21:37","date_gmt":"2023-08-24T12:21:37","guid":{"rendered":"https:\/\/ibex.tech\/c\/?p=1394"},"modified":"2024-05-08T12:17:58","modified_gmt":"2024-05-08T11:17:58","slug":"utc","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/c\/datetime\/utc","title":{"rendered":"UTC"},"content":{"rendered":"\n<p>UTC is the DateTime displayed in the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tyyyy-mm-ddThh:mm:ss\n\tyyyy-mm-dd hh:mm:ss<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert UTC char string to tm and tm to a UTC formatted char string<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;time.h&gt;\n\n\tstruct tm Tm1 = {0};\n\tchar TextBuffer&#91;50];\n\n\t\/\/Convert UTC string to tm\n\tchar MyUtcString&#91;50] = \"2020-08-01 11:05:13\";\n\tif (strptime(MyUtcString, \"%Y-%m-%d %H:%M:%S\", &amp;Tm1) == NULL)\t\t\/\/Convert the character string pointed to by buf to values which are stored in the tm structure pointed to by tm, using the format specified by format\n\t\tprintf(\"strptime Failed\\n\");\n\n\t\/\/The == NULL check will trigger if all the values aren't present, e.g. if you give a \"yyyy-mm-dd hh:mm\" string with a \"%Y-%m-%d %H:%M:%S\" format specifier it will return NULL because the seconds are missing\n\n\t\/\/Convert tm to string\n\tstrftime(TextBuffer, sizeof(TextBuffer), \"%Y-%m-%d %H:%M:%S\", &amp;Tm1);\n\tprintf(\"UTC: %s\\n\", TextBuffer);\n<\/code><\/pre>\n\n\n\n<p>Note, strftime() returns the total number of characters written (not including the terminating null-character), or zero on error. To get a pointer to the next character in the char string being written you can use this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;time.h>\n\n\/\/*****************************************************\n\/\/*****************************************************\n\/\/********** ADD UTC DATETIME TO CHAR STRING **********\n\/\/*****************************************************\n\/\/*****************************************************\nchar *AddUtcDateTimeToCharString (struct tm tmDateTime, char *pDest, char *pDestBufferEnd)\n{\n\tint Count;\n\n\tCount = strftime(pDest, ((pDestBufferEnd - pDest) + 1), \"%Y-%m-%d %H:%M:%S\", &amp;tmDateTime);\t\t\t\/\/Get timestamp\n\n\t\/\/Count = the total number of characters copied to ptr (not including the terminating null-character), or zero on error\n\n\tif (Count > 0)\n\t\treturn(pDest + Count);\n\telse\n\t\treturn(pDest);\t\t\t\/\/An error occured\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>UTC is the DateTime displayed in the following format: Convert UTC char string to tm and tm to a UTC formatted char string Note, strftime() returns the total number of characters written (not including the terminating null-character), or zero on error. To get a pointer to the next character in the char string being written [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118],"tags":[],"class_list":["post-1394","post","type-post","status-publish","format-standard","hentry","category-datetime"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=1394"}],"version-history":[{"count":14,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1394\/revisions"}],"predecessor-version":[{"id":1573,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1394\/revisions\/1573"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}