Win10物聯網開發的同事們!SSH通過代碼在Windows 10上設置日期IoT
我想寫一個程序來設置我的Raspberry Pi 3與Windows 10 IoT的時間,所以我的時間戳將是正確的。
我生成通過Renci.SshNet和喜歡那些代碼的SSH連接都完全正常工作:
Renci.SshNet.SshClient client = new SshClient(IP, Username, PW);
client.Connect();
client.RunCommand("TZUTIL /s \"W.Europe Standard Time\"");
client.RunCommand("shutdown /r /t 0");
但它是不可能的,我通過這組最新命令:
I tried all of the following:
// Manual
client.RunCommand("Set-Date " + ((char)34) + "08.06.2016 14:08:45" + ((char)34));
client.RunCommand("Set-Date \"10/3/2015 2:00PM\"");
// Dynamic
System.DateTime dateTime;
dateTime = System.DateTime.Now.AddHours(2);
String datestr = dateTime.ToString();
client.RunCommand("set-date \"" + datestr + "\"");
有是一個guide「如何通過殼命令連接」和命令 Set-Date "08.06.2016 14:31:00"
工作得很好,但相同的代碼不通過程序中的任何東西...
我很高興有任何幫助!
注:相關How to set system time in Windows 10 IoT?
「這是不可能的,我通過這組最新的命令「當你嘗試時會發生什麼?你有沒有收到任何錯誤信息?錯誤信息說什麼? – Kenster
你的'datestr'看起來像什麼?與08.06.2016 14:08:45'格式相同嗎?你有沒有試圖用自定義格式說明符和特定文化來設置它的格式呢? –
@Kenster 沒有錯誤消息,它只是停在那裏,直到Timer再次調用方法。它只是沒有設置我的樹莓上的時間既沒有提交「設置日期」命令和所有命令。 @SonerGönül Specific Culture同一問題: 'DateTime dt = DateTime.Now; Thread.CurrentThread.CurrentCulture = new CultureInfo(「de-DE」); CultureInfo ci = new CultureInfo(「de-DE」); client.RunCommand(「Set-Date \」「+ dt.ToString(ci)+」\「」);' 任何想法還可能是什麼? – Kyagos