{"id":3652,"date":"2022-11-11T11:24:24","date_gmt":"2022-11-11T11:24:24","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3652"},"modified":"2023-01-25T10:15:50","modified_gmt":"2023-01-25T10:15:50","slug":"current_time","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3652","title":{"rendered":"Current_time"},"content":{"rendered":"\n<p>This function gets the current time in UTC as a datetime object and adds &amp;offset hours to it.<\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">datetime current_time(number|string $offset)<\/code><\/pre>\n\n\n\n<p>Gets current time in UTC and adds $offset value in hours.<\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$offset:<\/strong> Amount of hours to add to current time. <br>$offset can be a string <code>'0'<\/code>, or a number <code>`0`<\/code>. <br>If $offset is a string, it must have integer format, i.e. must be a whole number. <br>If $offset is a number, it can be a double, i.e. hold decimals. However, the value will be converted to an integer. <code>`0.5`<\/code> rounds down.<br>There is no limit for $offset.<br>Negative sign can be prefixed to $offset i.e. <code>`-1`<\/code>.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \/\/No sample data needed\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    UTC: current_time(`0`),\n    UTCstring: current_time('0'),\n    UTCplus1: current_time(`1`),\n    UTCminus1: current_time(`-1`),\n    UTCplus25: current_time(`25`)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"UTC\": \"2022-11-10T12:51:49.4499414Z\",\n    \"UTCstring\": \"2022-11-10T12:51:49.4499547Z\",\n    \"UTCplus1\": \"2022-11-10T13:51:49.4499626Z\",\n    \"UTCminus1\": \"2022-11-10T11:51:49.4499669Z\",\n    \"UTCplus25\": \"2022-11-11T13:51:49.4499722Z\"\n}<\/code><\/pre>\n\n\n\n<p>This example showcases a variety of configuration options. No sample data is needed as UTC time is used as the data. Notice how &#8220;UTCplus25&#8221; adds a full day and one hour to the current time.<\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Synergy with format()<\/strong><\/p>\n\n\n\n<p>Before inserting datetime objects into a document, they likely need to be formatted. <a href=\"https:\/\/info.documotor.com\/?page_id=3753\">The format function<\/a> can be used to format the datetime object to a string value, like this:<\/p>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    UTC: current_time(`0`),\n    FormattedDate: format($.UTC, 'dd.MM.yyyy', 'en-US')\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"UTC\": \"2022-11-10T13:41:37.1224697Z\",\n    \"FormattedDate\": \"10.11.2022\"\n}<\/code><\/pre>\n\n\n\n<p>In above example, current datetime is defined as key &#8220;UTC&#8221;, and formatted using format() as key &#8220;FormattedDate&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This function gets the current time in UTC as a datetime object and adds &amp;offset hours to it. Syntax Gets current time in UTC and adds $offset value in hours. Parameters $offset: Amount of hours to add to current time. $offset can be a string &#8216;0&#8217;, or a number `0`. If $offset is a string, [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":271,"menu_order":21,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3652"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3652"}],"version-history":[{"count":6,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3652\/revisions"}],"predecessor-version":[{"id":3814,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3652\/revisions\/3814"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}