Converting date/time and generating offsets in bash script

Hi all,
I need a script to do some date/time conversion. It should take as an input a particular time. It should then generates a series of offsets, in both hour:minute form and number of milliseconds elapsed.

For 03:00, for example, it should give back 04:02:07 (3727000ms*) 05:04:14 (7454000ms), 06:06:21 etc...

How would I go about doing this as a bash script? Ideally it would work on both Mac OS X and Linux (Ubuntu or Debian).

  • (1hr * 60 minutes/hr 60 seconds/minute 1000ms/sec )+(2min60 sec/min * 1000ms/sec)+(7sec1000ms/sec) = (60*60*1000)+(2*60*1000)+(7*1000) = 3727000
#!/bin/bash

t=$(date -d "$1" +%s)

incr=3727
for cnt in {1..3} # Use this to increase/decrease number of offsets
do
    t_out=$((t + incr))
    echo "$(date -d @$t_out +"%H:%m:%S") -> $((($incr * 1000)))"
    (( incr = incr + 3727 ))
done

Usage: ./test.sh 03:00:00

Thanks, that helped a lot!