Is there a way to set system time from my app running on a Raspberry Pi 2 in Windows 10 IoT Core Insider Preview?
This doesn't work for lack of kernel32.dll
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
extern static bool Win32SetSystemTime(ref SystemTime sysTime);
First, connect to your Pi 2 using PowerShell.
Use the command set-date
to set the time. For example, if you want to set the date to Saturday, October 3, 2015, 2:00PM, you would type set-date 10/3/2015 2:00PM
.
The command tzutil
sets the time zone. Type tzutil /?
for usage
1-New Universal Project
2-Add Reference>Extensions>Windows IOT Extensions for UWP
3- Put a button, a datepicker and a timepicer control on your MainPage.xaml
and
private void buttonSetSystemDatetime_Click(object sender, RoutedEventArgs e)
{
DateTimeOffset dto = datePicker1.Date+ timePicker1.Time;
Windows.System.DateTimeSettings.SetSystemDateTime(dto);
}
4- in poject settings> set your target version and min version 10.0; build 16299
5- double click appxmanifest > Capabilities > check ON "System Management"
6- run app in IOT and press button. than return to default app. voila! system datetime changed.
note: rather to set it everytime. I offer you buy a cheap rtc (real time clock) module. (also needs extra coding)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With