Skip to content

Instantly share code, notes, and snippets.

@ltao31
Created February 8, 2024 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ltao31/1856b49b38f6c53d1445f22f960a6997 to your computer and use it in GitHub Desktop.
Save ltao31/1856b49b38f6c53d1445f22f960a6997 to your computer and use it in GitHub Desktop.
Calls a powershell script that gets system boot time and parses it into a structure
function [bootTime_struct] = getSystemBootTime(ps_path)
% get the system boot time
if isempty(ps_path)
[~,bootTime] = system(['powershell -command "' pwd '\Utils\GetSystemBootTime.ps1"']);
else
[~,bootTime] = system(['powershell -command "' ps_path '\GetSystemBootTime.ps1"']);
end
bootTime = splitlines(bootTime);
[bootTime,matches] = strsplit(bootTime{1},{'-','+'});
% split into year, month, day, hour, minutes, seconds, timezone
bootTime_struct.year = str2double(bootTime{1}(1:4));
bootTime_struct.month = str2double(bootTime{1}(5:6));
bootTime_struct.day = str2double(bootTime{1}(7:8));
bootTime_struct.hour = str2double(bootTime{1}(9:10));
bootTime_struct.min = str2double(bootTime{1}(11:12));
bootTime_struct.second = str2double(bootTime{1}(13:end));
bootTime_struct.timezone = str2double([matches{1} bootTime{end}]);
%bootTime_split = [s.y,s.mo,s.d,s.h,s.m,s.s,s.timezone];
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment