is it possible to convert from time format to an integer?
I need to convert the time it takes for a command to complete into seconds
e.g. 00:00:13.061801 to 13
Thanks
is it possible to convert from time format to an integer?
I need to convert the time it takes for a command to complete into seconds
e.g. 00:00:13.061801 to 13
Thanks
Yes. Get the seconds value from the current time by doing:
:pick [/system clock get time] 6 8
The following script is an example of how to calculate seconds elapsed. It does not work when crossing over midnight.
{
local startTime [/system clock get time];
# commands here
:delay 6s;
local endTime [/system clock get time];
# subtract startTime from endTime to get time elapsed
local finalTime ( $endTime - $startTime );
# convert hours to seconds, add to sum
:local sum ( $sum + ( [ :pick $finalTime 0 2 ] * 60 * 60 ));
# convert minutes to seconds, add to sum
:set sum ( $sum + ( [ :pick $finalTime 3 5 ] * 60 ));
# add seconds to sum
:set sum ( $sum + [ :pick $finalTime 6 8 ] );
:put "Seconds elapsed: $sum";
}