0

I grepped from the start time and end time strings from the program log. How can I find the time difference in hour?

t1="Tue Feb 21 12:15:00 HKT 2023"
t2="Tue Feb 21 12:45:01 HKT 2023"

I looked at other questions. But they have either different formats or directly from date like date -d 'now + 3 weeks'

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
SBMVNO
  • 103

1 Answers1

0

Like this:

#!/bin/bash

export TZ='Asia/Hong_Kong' oldd=$(date -d "Tue Feb 21 12:15:00 HKT 2023" "+%s") last=$(date -d "Tue Feb 21 12:45:01 HKT 2023" "+%s") diff=$((last - oldd)) echo "$((diff/3600 )) hours $(( (diff/60)%60 )) minutes $(( diff%60 )) seconds"

Output

0 hours 30 minutes 1 seconds