Set The System DateTime on Windows IoT

Menu > Project Add Reference > Universal Windows > Extensions > ensure ‘Windows IOT Extensions for UWP’ is checked

Double click Package.appxmanifest > Capabilities > ensure ‘System Management’ is checked

	//----- SET THE SYSTEM CLOCK -----
	DateTime DateTime1 = new DateTime(2007, 1, 12, 0, 0, 0);				//Set the required DateTime
	DateTimeOffset DateTimeOffset1 = new DateTimeOffset(DateTime1, TimeZoneInfo.Local.BaseUtcOffset);   //The TimeSpan sets the difference from UTC which is required for DateTimeOffset
	if (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime1))			//Handle currently in daylight saving time
		DateTimeOffset1 = DateTimeOffset1.AddHours(-1);
	Windows.System.DateTimeSettings.SetSystemDateTime(DateTimeOffset1);                         //Set the system DateTime

	//DateTime DateTime2 = DateTime.Now;			//Read the system DateTime

Setting from Date Picker

	private async void TimePicker1_TimePicked(object sender, TimePickedEventArgs e)
	{
		try
		{
			//----- GET THE TIME ENTERED -----
			TimeSpan TimeSpan1 = TimePicker1.Time;
			int Hour = TimeSpan1.Hours;
			int Minute = TimeSpan1.Minutes;

			//----- SET THE SYSTEM CLOCK -----
			DateTime DateTime1 = new DateTime(
				DateTime.Now.Year,
				DateTime.Now.Month,
				DateTime.Now.Day,
				Hour,
				Minute,
				0);
			DateTimeOffset DateTimeOffset2 = new DateTimeOffset(DateTime1, TimeZoneInfo.Local.BaseUtcOffset);   //The TimeSpan sets the difference from UTC which is required for DateTimeOffset
			if (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime1))			//Handle currently in daylight saving time
				DateTimeOffset2 = DateTimeOffset2.AddHours(-1);
			Windows.System.DateTimeSettings.SetSystemDateTime(DateTimeOffset2);                         //Set the system DateTime
		}
		catch (Exception ex)
		{
			System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
		}
	}
UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.