{"id":293,"date":"2016-12-22T11:13:18","date_gmt":"2016-12-22T11:13:18","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=293"},"modified":"2022-09-13T15:42:03","modified_gmt":"2022-09-13T14:42:03","slug":"utc-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/date-and-time-uwp-programming-in-c\/utc-2","title":{"rendered":"UTC"},"content":{"rendered":"\n<p>Converting a DateTime to Universal Time Format allows you to avoid local date time format issues when passing DateTime values between systems. Then just use Convert.ToDateTime to convert it back.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Get Current Time In UTC<\/h4>\n\n\n\n<p>Use .UtcNow instead of .Now<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tDateTime TimeNow = new DateTime();\n\tTimeNow = DateTime.UtcNow;\n\tstring currentDateTime = TimeNow.ToString(\"yyyy-MM-ddTHH:mm:ss\");<\/code><\/pre>\n\n\n\n<p>Simpler:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MyString = DateTime.UtcNow.ToString(\"yyyy-MM-ddTHH:mm:ss\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert UTC To Local Format<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tDateTime dateTime1 = Convert.ToDateTime(MyDateTimeInUtc);\n\tstring myDateTime = dateTime1.ToString();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Converting a DateTime to Universal Time Format allows you to avoid local date time format issues when passing DateTime values between systems. Then just use Convert.ToDateTime to convert it back. Get Current Time In UTC Use .UtcNow instead of .Now Simpler: Convert UTC To Local Format<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[138],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-date-and-time-uwp-programming-in-c"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":1189,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/293\/revisions\/1189"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}