I am currently experiencing 2 problems with the mac date command.
I am running a shell script which first executes the command (ps -p $p_id -o etime=) to give me the elapsed time of a process with p_id, which returns a date of the form [[dd-]hh:]mm:ss
Problem 1: The following command to convert a date to another format seems to be causing weird problems: (date -j -f "%H:%M:%s" "$processStartTime" "+%H:%M:%s"). Say the prcoessStartTime=12:30:33. The output date this command returns is 01:00:33 even though I'm converting the date to the same format. It only gets the seconds right and the hours and minutes are wrong. If i use different quotation marks like '' surrounding the date format, i get even stranger results! The goal is to convert the time into minutes so i can see how many minutes the process has been running for.
Problem 2: Since the process date can be in the following format [[dd-]hh:]mm:ss how should i handle different date formats in my code? Should i have 3 conditions to check the format? or is there a way to handle this? i.e. some dates might be of the form hh:mm:ss and others mm:ss, and i need to have the input date format correct in the command otherwise it throws an error.
%Sin caps instead of%s?%sreturns seconds since the epoch. I wonder what strptime is doing with it. What doesdate -j -f "%H:%M:%s" "$processStartTime"show?