Convert a value obtained in Hours: Minutes: Second to Hours: Minutes


Hello, I currently have a value obtained that gives me in Hours: Minutes: Seconds what I want is to Convert it into Hours: Minutes

//Valor Obtenido por el id
 var HoraActuales = $('input:text[id=COMD_FECHA]').val();
 console.log(HoraActuales)//=> Sale un ejemplo 10:40:9 
 //Lo que quiero es hacer que sea 10:40
asked by Chris Alexis 05.10.2018 в 18:06

4 answers

//Intenta tomar el valor del input así:
var HoraActuales = $('input#COMD_FECHA').val();

//Lo que tienes que hacer es tomar los primeros caracteres que quieres mostrar
//Usa la función substring()
answered by 05.10.2018 / 18:20

It's easy if you only work with html css and js you can add moment.js download if you are using nodejs you can install it with npm install moment --save # npm for more information about moment.js see the documentation

  // instantiate a moment object
  var NowMoment = moment().format('h:mm'); // October 5th 2018, 2:41:19 am
  // instantiate a JavaScript Date object
  var NowDate = new Date();
  // display value of moment object in #displayMoment div
  var eDisplayMoment = document.getElementById('displayMoment');
  eDisplayMoment.innerHTML = NowMoment;
  // display value of Date object in #displayJsDate div
  var eDisplayDate = document.getElementById('displayJsDate');
  eDisplayDate.innerHTML = NowDate;
<script src=""></script>
<h2>JavaScript Date</h2>
<!-- container for JavaScript Date output -->
<div id="displayJsDate"></div>

<h2>Moment Date</h2>
<!-- container for Moment.js output -->
<div id="displayMoment"></div>
answered by 05.10.2018 в 20:59
       <div class="col-md-2">
                            <div class="form-group">
                                <label>Fecha de Atención</label>
                                <input type="text" class="form-control" id="COMD_FECHA_ATENCION" name="COMD_FECHA_ATENCION" value="@Model.COMD_FECHA_ATENCION.ToString("dd/MM/yyyy")" />
                         <div class="col-md-2">
                            <div class="form-group">
                                <label for="COMD_FECHA">Hora de Atención</label>
                                <input type="hidden" id="txtHoraEAtencion" value="@Model.COMD_FECHA.ToString("HH:mm")">
                                <input type="text" class="form-control" id="COMD_FECHA" name="COMD_FECHA" value="@Model.COMD_FECHA" />
answered by 05.10.2018 в 18:45

Try this, here I leave the code, I assume the variable you receive is string:

<!DOCTYPE html>
<script src=""></script>

<p>Click the button to extract characters from the string.</p>

<button onclick="myFunction()">Intentalo</button>

<p id="resuesta"></p>
<input type="text"  id="COMD_FECHA" name="COMD_FECHA" value='10:40:9' />

function myFunction() {
    var temp=$('#COMD_FECHA').val().toString().substr(0,5)
    document.getElementById("resuesta").innerHTML = temp;

answered by 08.10.2018 в 23:57