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

163
Vistas
Adding a variable time field (24 format) and a variable datetime field (m/d/yy h:MM tt) to produce result in another field

Please help! I am a very novice JavaScript user and have scoured the forums trying to find an answer to my problem:

I have two fields that are variable I am trying to add them together in a separate field. One field (TotHr) is in HH:MM format, and the other is a datetime field (DTin1) that is in m/d/yy h:MM tt format. I need the output to read in the same format as the datetime field. This will be utilized on various consoles throughout my work, so I would like to not use a library like moment.js.

Here is what I have so far:

var date = new Date();
var dateMil = date.getTime("DTin1");
var timePeriod = ("TotHr");

var parts = timePeriod.split(/:/);
var timePeriodMil = (parseInt(parts[0], 10) * 60 * 60 * 1000) +
                (parseInt(parts[1], 10) * 60 * 1000) + 
                (parseInt(parts[2], 10) * 1000);

var newDate = new Date();
newDate.setTime(dateMil + timePeriodMil);

console.log(newDate);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are many ways to do it in JavaScript. A simple way is to use some library e.g. the following code uses moment.js library.

const { duration } = require('moment')
const moment = require('moment-timezone')

let strDuration = "10:30"
let strDateTime = "9/6/21 5:10 am"
let format = 'M/D/YY h:m a'

dur = moment.duration(strDuration)
dt = new moment(strDateTime, format)

result = dt.add(dur).tz('Europe/London').format(format)

console.log(result)

Output:

9/6/21 3:40 pm
about 4 years ago · Juan Pablo Isaza 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