Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
SHELL: How can I convert a string to timestamp

I'd like to convert string below into timestamp, I already did this into Sheets but I would like to automate this process.

FROM: 38740

TO: 00:38.74

In google sheets, I insert the formula and works perfectly

=TEXT(A2/86400000,"mm:ss.00")

In shell (bash):

awk "BEGIN {print 38740/86400000}"

There's one way to do that using shell or I need to use some programming language more advanced?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Another Bash approach

t=$(bc <<< 'scale=2; 38740/1000')
d=$(date -d @"$t" --utc '+%M:%S.%N')
echo "${d:0:9}"
00:38.740
over 4 years ago · Santiago Trujillo Report

0

With bash, using the builtin arithmetic

str=38740
(( mins = str / 60000, str %= 60000, secs = str / 1000, msec = str % 1000 ))
printf -v duration "%02d:%02d.%03d" "$mins" "$secs" "$msec"
echo "$duration"
# => 00:38.740

Encapsulated into a function:

milliseconds_to_duration () {
    local mins secs msec
    local tmp=$1
    (( mins = tmp / 60000, tmp %= 60000, secs = tmp / 1000, msec = tmp % 1000 ))
    printf "%02d:%02d.%03d\n" "$mins" "$secs" "$msec"
}

then

$ milliseconds_to_duration 38740
00:38.740
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!