none
How do I set the time in Winodws ioT ? RRS feed

  • Question

  • I have a Raspberry Pi 2 with Windows 10 ioT.  How do I set the time of the device using C#  ?

    Thanks

    P.S. If not possible, is there a way for me to set the timezone ?


    Bill Greer


    Thursday, August 6, 2015 11:39 AM

Answers

  • Absolutely!

    You can use powershell to set it up.

    http://ms-iot.github.io/content/en-US/win10/samples/PowerShell.htm

    To see the timezone and set it:

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /g}
    Eastern Standard Time

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /s "Pacific Standard Time"}

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /g}
    Pacific Standard Time

    To get and set the time:

    jpswin10rpi2]: PS C:\Users\Administrator\Documents> Get-Date

    Thursday, August 6, 2015 11:18:26 AM

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Set-Date "Thursday, August 6, 2015 2:18:26 AM"

    Thursday, August 6, 2015 2:18:26 AM

    Changing the TZ does not adjust the time for you!


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 6, 2015 6:20 PM

All replies

  • You cannot affect the system settings from a Universal App. 

    What is your scenario here that requires you to change the date time from what it would be set from the network time service for instance?


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 6, 2015 2:56 PM
  • I time stamp some events before I send them up to a server.  The time is off by a couple hours so I am guessing the Time Zone is incorrect on my device (Raspberry Pi 2 with Windows 10 ioT).  Is there a way to check and change the Time Zone ?  If not, then I will just use some code to offset it.

    Bill Greer

    Thursday, August 6, 2015 6:03 PM
  • Absolutely!

    You can use powershell to set it up.

    http://ms-iot.github.io/content/en-US/win10/samples/PowerShell.htm

    To see the timezone and set it:

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /g}
    Eastern Standard Time

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /s "Pacific Standard Time"}

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Invoke-Command {tzutil /g}
    Pacific Standard Time

    To get and set the time:

    jpswin10rpi2]: PS C:\Users\Administrator\Documents> Get-Date

    Thursday, August 6, 2015 11:18:26 AM

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Set-Date "Thursday, August 6, 2015 2:18:26 AM"

    Thursday, August 6, 2015 2:18:26 AM

    Changing the TZ does not adjust the time for you!


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 6, 2015 6:20 PM
  • I'm not sure why you would use invoke-command when just doing it locally on the raspberry.

    To keep it simple, just do the tzinfo bits:

    - 'tzinfo /g' shows the current zone.

    - 'tzinfo /l' lists the available zones.

    - 'tzinfo /s "zone name"' sets the new zone (a reboot is required after this step).

    Also, to have it try to determine the time itself try 'w32tm /resync /rediscover'. It is also something you probably want to do after turning the pi on again if it's been shut down.



    Thursday, August 6, 2015 6:33 PM
  • Correct Torg.  I grabbed it from a remote script I had.  You do not need the Invoke-Command.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 6, 2015 6:48 PM
  • I can set the time zone now, but I try to set the time and it stays the same.  What gives ?

    [jpswin10rpi2]: PS C:\Users\Administrator\Documents> Set-Date "Thursday, August 6, 2015 2:18:26 AM"


    Bill Greer

    Tuesday, August 25, 2015 5:45 PM
  • Create a file "SyncTime.ps1" on the Pi containing the PowerShell script to run "w32tm /resync /force".

    Then run this script to create a scheduled task that runs it on start up.

    schtasks /Create /SC ONSTART /TN TimeSync /TR c:\SyncTime.ps1

    That will force it to sync the time when it starts up.  It seems this registry key below also needs to be set to your NTP server that it's going to sync to.  Mine is set to our domain controller and it's working fine.

    set-itemproperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters -Name NtpServer -Value 127.0.0.1,0x9


    Tuesday, August 25, 2015 9:04 PM
  •  MarbryHardin great post.  I am excited about using PowerShell scripts and scheduled tasks in Windows 10 IoT.  Does Windows 10 IoT have a scheduled task log that I can view ?  

    Bill Greer

    Wednesday, August 26, 2015 4:31 PM
  • You can run just schtasks and it will show you all of the tasks with their next run time.

    I'm not sure about any kind of history, it may be buried in there somewhere.

    Wednesday, August 26, 2015 6:29 PM
  • To keep it simple, just do the tzinfo bits:

    - 'tzinfo /g' shows the current zone.

    - 'tzinfo /l' lists the available zones.

    - 'tzinfo /s "zone name"' sets the new zone (a reboot is required after this step).

    C:\Users\Administrator\Documents>tzinfo
    'tzinfo' is not recognized as an internal or external command,
    operable program or batch file.

    RPi2 + IoT.

    You probably mean 'tzutil'.


    • Edited by DimoniraTN Wednesday, August 26, 2015 8:39 PM
    Wednesday, August 26, 2015 8:05 PM
  • This was working great for a couple weeks.  I suspected an issue today so I ran w32tm /resyn /force against my controllers and they all return "The computer did not resync because no time data was available."  

    I tried stopping and starting the w32tm service and un-registering and re- registering the service with no luck.  I also tried using different time servers.  This leads me to believe that there is an issue with my network.  

    Is there a way I can run "Set-Date" against the controllers remotely, sending in the correct Date Time ?  It would be unattended so I would need to pass in credentials as well. 


    Bill Greer

    Monday, September 28, 2015 3:21 PM
  • Can you ping the time server(s) from the Pi, and vice versa?  Do you have a static IP set?  Did the Pi get segmented off on a separate vlan or something?

    This *is* the way to run that unattended as far as I know, you probably need to figure out why the call suddenly started failing.

    Monday, September 28, 2015 5:35 PM
  • I have a scenario where I am creating a system of smart devices (each contains a raspberry pi). The devices are guaranteed to have access to a common router (LAN), but not necessarily the internet (to allow use in remote locations). When the server starts up it uses a custom UDP broadcasting system to discover all the devices that are on the local network. Once a device is discovered I create a TCP connection to the device to gather further details. At this point, I would like the server to broadcast it's time to the devices so that they can sync up (only needs to be in sync at the resolution of seconds).

    What i need is a way, in C#, to set the date and time based on the message from the server.

    Should I be generating and executing a script with c#?


    Monday, October 3, 2016 11:46 PM
  • I need to be able to change the time of the system for when the Raspberry Pi 3 turn on offline, because the system does not track the time, when turned off.

    Any ideas?

    Wednesday, October 12, 2016 4:27 PM
  • Get a RTC board, like this: https://thepihut.com/products/mini-rtc-module-for-raspberry-pi?variant=758601217

    (just the first hit when I googled)

    There are several options available, a former colleague of mine bought one that also had the ability to turn the pi on again after a given time (or at a given time? not sure).

    Thursday, October 13, 2016 6:47 AM