Design a Time Duration Calculator Card in Tailwind CSS & JavaScript Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we'll create a simple Time Duration Calculator application using the Tailwind CSS and JavaScript. The application allows users to add a starting date & time and an ending date & time. And user gets the difference between these two dates as a output. We'll utilize Tailwind CSS for styling to create an attractive user interface and JavaScript for the logic. Approach to create Time Duration Calculator CardCreate an HTML file named index.html and link the Tailwind CSS stylesheet for styling.Design the input area where user will input the starting and ending date & time.Create a file named script.js, and write JavaScript code inside it to handle form submission.Implement JavaScript logic to calculate the duration between start and end times entered by the user.Example: This example describes the implementation of a basic Time Duration Calculator using Tailwind CSS, and Javascript. HTML <!DOCTYPE html> <html lang="en"> <head> <title>The Time Duration Calculator</title> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet"> </head> <body class="bg-gray-100 flex items-center justify-center h-screen"> <div class="max-w-md flex items-center flex-col bg-white rounded-lg shadow-lg border-2 border-green-500 p-8"> <!-- Heading --> <h1 class="text-3xl font-bold text-center mb-8"> Time Duration Calculator </h1> <!-- Start date Input Section --> <div class="mb-4 flex gap-10 items-end"> <label for="startTime" class="text-gray-700 block mb-2"> Start Time </label> <input type="datetime-local" id="startTime" class="input-field border border-green-500 rounded-lg p-2"> </div> <!-- Finish date Input Section --> <div class="mb-4 flex gap-8 items-end"> <label for="endTime" class="text-gray-700 block mb-2"> Finish Time </label> <input type="datetime-local" id="endTime" class="input-field border border-green-500 rounded-lg p-2"> </div> <!-- Calculate Button --> <button class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded-md w-full focus:outline-none" id="calculateButton"> Calculate Duration </button> <!-- Result Section --> <div class="result text-center text-lg font-semibold mt-4 hidden" id="result"> </div> </div> <script src="script.js"></script> </body> </html> JavaScript // file - script.js document.getElementById('calculateButton').addEventListener('click', () => { // Fetching the data const startTime = new Date(document.getElementById('startTime') .value) .getTime(); const endTime = new Date(document.getElementById('endTime').value).getTime(); // Checking if user have given any input or not if (isNaN(startTime) || isNaN(endTime)) { document.getElementById('result') .textContent = "Please enter valid dates."; document.getElementById('result').classList.remove('hidden'); } else { // Calculating the time difference const duration = Math.abs(endTime - startTime); const days = Math.floor(duration / (1000 * 60 * 60 * 24)); const hours = Math.floor(( duration % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60 )); const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((duration % (1000 * 60)) / 1000); // Showing the result document.getElementById('result').textContent = `${days} days :: ${hours} hours :: ${minutes} minutes :: ${seconds} seconds`; document.getElementById('result').classList.remove('hidden'); } }); Output: Time Duration Calculator using Tailwind CSS Comment More infoAdvertise with us Next Article Factorial Calculator Card using Tailwind CSS and JavaScript M mguru4c05q Follow Improve Article Tags : JavaScript Similar Reads EMI Calculator Card using Tailwind CSS and JavaScript An EMI (Equated Monthly Installment) calculator helps users determine the monthly payment amount towards a loan including both the principal amount and the interest. This project will demonstrate how to create a simple yet effective financial tool using the Tailwind CSS framework. Approach to create 3 min read Factorial Calculator Card using Tailwind CSS and JavaScript The Factorial Calculator is a web application designed to calculate the factorial of a non-negative integer entered by the user and instantly compute its factorial upon a button click. If the user wants to start over, they can utilize the "Clear" button. Its design and user-friendly features ensure 3 min read Design a Inverse t Distribution Calculator in Tailwind CSS This project is an Inverse t-distribution Calculator implemented using HTML, CSS (Tailwind CSS), and JavaScript. It allows users to calculate the inverse t-distribution for the given probability (p) and degrees of freedom (DOF). Prerequisites / Technologies Used:HTMLCSS (Tailwind CSS)JavaScriptAppro 3 min read LCM & GCD Calculator Card using Tailwind CSS & JavaScript The LCM and GCD Calculator is a web application that allows users to calculate the Least Common Multiple (LCM) and Greatest Common Divisor (GCD) of the two numbers. Users input two numbers and the application computes and displays their LCM and GCD. Approach to create LCM & GCD Calculator CardCr 3 min read Tip Calculator Card using Tailwind CSS & JavaScript Tip Calculator in Tailwind CSS is a simple and user-friendly tool designed to help users calculate tips for various services. It allows users to input the total bill amount, select a tip percentage, and choose the number of people splitting the bill. The calculator then displays the tip amount, the 3 min read BMI Calculator Card using Tailwind CSS & JavaScript The Body Mass Index (BMI) Calculator can be used to calculate BMI values based on height and weight. BMI is a fairly reliable indicator of body fatness for most people. In this article, we will implement a BMI (Body Mass Index) Calculator using JavaScript with Tailwind CSS framework. Formula to calc 3 min read Like