Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

402
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda