{"id":445,"date":"2017-01-18T22:53:04","date_gmt":"2017-01-18T22:53:04","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=445"},"modified":"2022-09-13T15:42:18","modified_gmt":"2022-09-13T14:42:18","slug":"setting-the-system-clock","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/date-and-time-uwp-programming-in-c\/setting-the-system-clock","title":{"rendered":"Setting The System Clock"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Set The System DateTime on Windows IoT<\/h4>\n\n\n\n<p>Menu &gt; Project Add Reference &gt; Universal Windows &gt; Extensions &gt; ensure &#8216;Windows IOT Extensions for UWP&#8217; is checked<\/p>\n\n\n\n<p>Double click Package.appxmanifest &gt; Capabilities &gt; ensure &#8216;System Management&#8217; is checked<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/----- SET THE SYSTEM CLOCK -----\n\tDateTime DateTime1 = new DateTime(2007, 1, 12, 0, 0, 0);\t\t\t\t\/\/Set the required DateTime\n\tDateTimeOffset DateTimeOffset1 = new DateTimeOffset(DateTime1, TimeZoneInfo.Local.BaseUtcOffset);   \/\/The TimeSpan sets the difference from UTC which is required for DateTimeOffset\n\tif (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime1))\t\t\t\/\/Handle currently in daylight saving time\n\t\tDateTimeOffset1 = DateTimeOffset1.AddHours(-1);\n\tWindows.System.DateTimeSettings.SetSystemDateTime(DateTimeOffset1);                         \/\/Set the system DateTime\n\n\t\/\/DateTime DateTime2 = DateTime.Now;\t\t\t\/\/Read the system DateTime\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting from Date Picker<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tprivate async void TimePicker1_TimePicked(object sender, TimePickedEventArgs e)\n\t{\n\t\ttry\n\t\t{\n\t\t\t\/\/----- GET THE TIME ENTERED -----\n\t\t\tTimeSpan TimeSpan1 = TimePicker1.Time;\n\t\t\tint Hour = TimeSpan1.Hours;\n\t\t\tint Minute = TimeSpan1.Minutes;\n\n\t\t\t\/\/----- SET THE SYSTEM CLOCK -----\n\t\t\tDateTime DateTime1 = new DateTime(\n\t\t\t\tDateTime.Now.Year,\n\t\t\t\tDateTime.Now.Month,\n\t\t\t\tDateTime.Now.Day,\n\t\t\t\tHour,\n\t\t\t\tMinute,\n\t\t\t\t0);\n\t\t\tDateTimeOffset DateTimeOffset2 = new DateTimeOffset(DateTime1, TimeZoneInfo.Local.BaseUtcOffset);   \/\/The TimeSpan sets the difference from UTC which is required for DateTimeOffset\n\t\t\tif (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime1))\t\t\t\/\/Handle currently in daylight saving time\n\t\t\t\tDateTimeOffset2 = DateTimeOffset2.AddHours(-1);\n\t\t\tWindows.System.DateTimeSettings.SetSystemDateTime(DateTimeOffset2);                         \/\/Set the system DateTime\n\t\t}\n\t\tcatch (Exception ex)\n\t\t{\n\t\t\tSystem.Diagnostics.Debug.WriteLine(\"Exception: \" + ex.Message);\n\t\t}\n\t}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Set The System DateTime on Windows IoT Menu &gt; Project Add Reference &gt; Universal Windows &gt; Extensions &gt; ensure &#8216;Windows IOT Extensions for UWP&#8217; is checked Double click Package.appxmanifest &gt; Capabilities &gt; ensure &#8216;System Management&#8217; is checked Setting from Date Picker<\/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-445","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\/445","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=445"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":1190,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/445\/revisions\/1190"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}