• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Web Server Course Project 3.2

Q&A Forum › Category: ESP32 › Web Server Course Project 3.2
0 Vote Up Vote Down
Edward Wilson asked 3 years ago

I am currently working on Project 3.2 in the Web Server course. This project uses javascript to determine the date and time of the last update of the sensor readings. Unfortunately, the resulting time display contains only one digit for minutes and seconds when the value is less than 10. Could anyone suggest a “clean” way of adding a leading “0” to single digit minutes and seconds for this case?
 
Thanks,
 
Ed Wilson

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
That needs to be fixed.
The updateDateTime() JavaScript function should be like this:

function updateDateTime() {
  var currentdate = new Date();
  var datetime = currentdate.getDate() + "/"
    + ("00" + (currentdate.getMonth()+1)).slice(-2) + "/"
    + currentdate.getFullYear() + " at "
    + ("00" + currentdate.getHours()).slice(-2)  + ":"
    + ("00" + currentdate.getMinutes()).slice(-2) + ":"
    + ("00" + currentdate.getSeconds()).slice(-2);
    document.getElementById("update-time").innerHTML = datetime;
    console.log(datetime);
}

Regards
Sara

0 Vote Up Vote Down
Edward Wilson answered 3 years ago

Sara,
 
You are just a “fountain” of knowledge…thank you so much! You may mark this question as resolved.
 
Ed Wilson

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

You’re welcome.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.