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

153
Views
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 answers
Answer question

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 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!