Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set system time in Windows 10 IoT?

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);
like image 698
raven-ai Avatar asked Jun 02 '15 01:06

raven-ai


2 Answers

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

like image 116
kiran Avatar answered Oct 13 '22 00:10

kiran


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)

like image 43
Zen Of Kursat Avatar answered Oct 13 '22 01:10

Zen Of Kursat