diff --git a/Calculators/Military-Time-Calculator/README.md b/Calculators/Military-Time-Calculator/README.md new file mode 100644 index 000000000..1bc63fc97 --- /dev/null +++ b/Calculators/Military-Time-Calculator/README.md @@ -0,0 +1,41 @@ +#

Military Time Calculator

+ +## Description :- + +The Military Time Calculator is a simple web application designed to help users convert between standard 12-hour time format and military 24-hour time format. This tool is particularly useful for individuals in the military, aviation, and other fields where precise time communication is critical. + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## How It Works :- + +The Military Time Calculator uses straightforward algorithms to perform time conversions. Here's a high-level overview: + +1. **Input Time:** Users enter the time in either 12-hour (AM/PM) format or 24-hour format into the input field. +2. **Selection of Conversion:** Users select the direction of conversion (12-hour to 24-hour or 24-hour to 12-hour). +3. **Validation:** The application validates the input to ensure it is in the correct format. +4. **Conversion:** The time is converted using basic arithmetic and string manipulation. +5. **Display Result:** The converted time is displayed to the user. + +## Features :- + +- Convert 12-hour AM/PM time to 24-hour military time. +- Convert 24-hour military time to 12-hour AM/PM time. +- Simple and intuitive user interface. +- Input validation to ensure accurate conversions. + +## Example :- + +- **Converting 12-hour to 24-hour** + - Input: 02:30 PM + - Output: 14:30 +- **Converting 24-hour to 12-hour** + - Input: 14:30 + - Output: 02:30 PM + +## Screenshots :- + +![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/9200c6d5-14b6-4462-845a-01ff68a0ce56) diff --git a/Calculators/Military-Time-Calculator/index.html b/Calculators/Military-Time-Calculator/index.html new file mode 100644 index 000000000..aa7c3aa51 --- /dev/null +++ b/Calculators/Military-Time-Calculator/index.html @@ -0,0 +1,32 @@ + + + + + + + + Military Time Calculator + + + +
+

Military Time Calculator

+
+
+ + + +

+
+
+ + + +

+
+
+
+ + + + diff --git a/Calculators/Military-Time-Calculator/script.js b/Calculators/Military-Time-Calculator/script.js new file mode 100644 index 000000000..4c8b94b05 --- /dev/null +++ b/Calculators/Military-Time-Calculator/script.js @@ -0,0 +1,43 @@ +function convertToMilitary() { + const standardTime = document.getElementById('standardTime').value.trim(); + const timeParts = standardTime.match(/(\d+):(\d+)\s?(AM|PM)/i); + + if (!timeParts) { + alert('Please enter a valid standard time (e.g., 02:30 PM).'); + return; + } + + let [_, hours, minutes, period] = timeParts; + hours = parseInt(hours); + minutes = parseInt(minutes); + period = period.toUpperCase(); + + if (period === 'PM' && hours < 12) { + hours += 12; + } else if (period === 'AM' && hours === 12) { + hours = 0; + } + + const militaryTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + document.getElementById('militaryTimeOutput').innerText = `Military Time: ${militaryTime}`; +} + +function convertToStandard() { + const militaryTime = document.getElementById('militaryTime').value.trim(); + const timeParts = militaryTime.match(/(\d+):(\d+)/); + + if (!timeParts) { + alert('Please enter a valid military time (e.g., 14:30).'); + return; + } + + let [_, hours, minutes] = timeParts; + hours = parseInt(hours); + minutes = parseInt(minutes); + + const period = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12 || 12; + + const standardTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')} ${period}`; + document.getElementById('standardTimeOutput').innerText = `Standard Time: ${standardTime}`; +} diff --git a/Calculators/Military-Time-Calculator/style.css b/Calculators/Military-Time-Calculator/style.css new file mode 100644 index 000000000..0dd488648 --- /dev/null +++ b/Calculators/Military-Time-Calculator/style.css @@ -0,0 +1,82 @@ +body { + font-family: 'Arial', sans-serif; + background: linear-gradient(135deg, #667eea, #764ba2); + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + color: #fff; +} + +.container { + background: rgba(255, 255, 255, 0.1); + padding: 40px; + border-radius: 10px; + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); + width: 90%; + max-width: 500px; + text-align: center; +} + +h1 { + margin-bottom: 20px; + font-size: 24px; + color: #fff; + text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); +} + +.calculator { + display: flex; + flex-direction: column; + gap: 20px; +} + +.time-conversion { + display: flex; + flex-direction: column; + align-items: center; +} + +label { + margin-bottom: 10px; + font-weight: bold; + font-size: 16px; + color: #fff; +} + +input { + padding: 10px; + border: none; + border-radius: 4px; + margin-bottom: 10px; + width: 100%; + max-width: 300px; + text-align: center; + background: rgba(255, 255, 255, 0.8); + color: #333; + font-size: 16px; +} + +button { + padding: 10px 20px; + background: #ff5722; + color: white; + border: none; + border-radius: 20px; + cursor: pointer; + font-size: 16px; + transition: background 0.3s; + text-transform: uppercase; +} + +button:hover { + background: #e64a19; +} + +p { + margin-top: 10px; + font-size: 18px; + color: #fff; + text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); +} diff --git a/index.html b/index.html index 0dda634ab..985180ee5 100644 --- a/index.html +++ b/index.html @@ -1716,10 +1716,24 @@

Your key to matrix operations!

+
+
+

Military Time Calculator

+

Converts between standard 12-hour time format and military 24-hour time format.

+ +
+

Molecular Weight Calculator

-

Computes the total atomic weights of elements in a given chemical formula

+

Computes the total atomic weights of elements in a given chemical formula.