Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Showing Time duration using JQuery with Current Date time

In my web application, I show the user the request posted date time in the view.

I want to additionally show how long ago that was posted with Date time now.

What is the easiest way to show it

This is the Code

<div class="timeline">
  <div class="time-label">
    <span class="bg-green">
      <label id="dateRequested">@Model.First().Approved_Date</label>
    </span>
  </div>
  <div>
    <i class="fas fa-envelope bg-blue"></i>
    <div class="timeline-item">
      <span class="time">
        <i class="fas fa-clock"></i>
      </span>
    </div>
    <i class="fas fa-user bg-green"></i>
    <div class="timeline-item">
      <span class="time">
        <i class="fas fa-clock"></i> 5 mins ago </span>
      <h3 class="timeline-header no-border">
        <a href="#">Managers</a> Previously Approved By
      </h3>
    </div>
  </div>
</div>

<script type="text/javascript">

    const date = $('#dateRequested');
    console.log(date);
    // Do your operations
    const currentTime = new Date();
    console.log(currentTime);
    const seconds = (currentTime.getTime() - date.getTime()) / 1000;
    console.log(seconds);


</script>

@Model.First().Approved_Date (this shows as (12/23/2021 12:10:11 PM)) here shows the posted date and I want to get the difference between that date with Date time now and show the difference in the 5 mins ago place. Can I get help to create this? Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const date = 'date that you have';
// Do your operations
const currentTime   = new Date();
const seconds = (currentTime.getTime() - date.getTime()) / 1000;

This will give you the seconds from the time you started til now. Now what you can do is that you can convert the seconds into minutes, hours or whatever you want.

Hope that this helped you solve your problem.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda