Master time conversion for software development, project management, and everyday calculations with practical examples and best practices.
| From | To | Formula | Example |
|---|---|---|---|
| Weeks | Days | × 7 | 2 weeks = 14 days |
| Days | Hours | × 24 | 3 days = 72 hours |
| Hours | Minutes | × 60 | 2 hours = 120 minutes |
| Minutes | Seconds | × 60 | 5 minutes = 300 seconds |
| Seconds | Milliseconds | × 1000 | 3 seconds = 3000 ms |
| Days | Milliseconds | × 86,400,000 | 1 day = 86,400,000 ms |
Setting a timeout for 5 minutes:
// Convert 5 minutes to milliseconds
const fiveMinutes = 5 * 60 * 1000; // = 300,000 ms
setTimeout(() => {
console.log('5 minutes have passed!');
}, fiveMinutes);
Pro tip: Use our time converter to quickly get the millisecond value.
Limiting API calls to 100 requests per hour:
// Calculate milliseconds between requests
const requestsPerHour = 100;
const millisecondsPerHour = 60 * 60 * 1000; // = 3,600,000
const delayBetweenRequests = millisecondsPerHour / requestsPerHour;
console.log(delayBetweenRequests); // 36,000 ms (36 seconds)
Setting cache to expire after 24 hours:
// Python example
cache_duration_seconds = 24 * 60 * 60 # 86,400 seconds
cache.set('user_data', data, timeout=cache_duration_seconds)
// JavaScript example
const cacheDurationMs = 24 * 60 * 60 * 1000; // 86,400,000 ms
localStorage.setItem('timestamp', Date.now() + cacheDurationMs);
A 2-week sprint in different time units:
💡 Tip: Always clarify whether you're using calendar days (7 per week) or business days (5 per week) when estimating project timelines.
A project requires 240 person-hours. With a team of 3 developers working 8-hour days:
-- SQL example
SELECT * FROM orders
WHERE created_at >= NOW() - INTERVAL 7 DAY;
-- Or using timestamp comparison (in seconds)
WHERE created_at >= UNIX_TIMESTAMP() - (7 * 24 * 60 * 60);
7 days = 604,800 seconds = 604,800,000 milliseconds
// JavaScript
const start = performance.now();
expensiveFunction();
const end = performance.now();
const durationMs = end - start;
const durationSeconds = durationMs / 1000;
console.log(`Executed in ${durationSeconds.toFixed(3)} seconds`);
Temperature sensor reading every 5 minutes with data transmission every hour:
// Reading every 5 minutes (300,000 ms)
const unsigned long READING_INTERVAL = 5UL * 60 * 1000;
void loop() {
static unsigned long lastReading = 0;
unsigned long now = millis();
if (now - lastReading >= READING_INTERVAL) {
readTemperature();
lastReading = now;
}
}
⚠️ Mistake 1: Confusing seconds with milliseconds in JavaScript
// WRONG - will timeout immediately
setTimeout(callback, 5); // Only 5 milliseconds!
// CORRECT - 5 seconds
setTimeout(callback, 5000); // 5,000 milliseconds = 5 seconds
⚠️ Mistake 2: Not accounting for business days
When a client says "2 weeks," they might mean:
Always clarify!
⚠️ Mistake 3: Floating point precision errors
// May have precision issues with very large numbers
const nanoseconds = seconds * 1000000000;
// Better: Use BigInt for very large values
const nanoseconds = BigInt(seconds) * 1000000000n;
// Good: Self-documenting code
const MILLISECONDS_PER_SECOND = 1000;
const SECONDS_PER_MINUTE = 60;
const MINUTES_PER_HOUR = 60;
const HOURS_PER_DAY = 24;
const oneDayInMs = HOURS_PER_DAY * MINUTES_PER_HOUR *
SECONDS_PER_MINUTE * MILLISECONDS_PER_SECOND;
// Bad: Magic numbers
const oneDayInMs = 86400000; // What is this?
// Cache expires after 7 days (604,800,000 ms)
cache.set('data', value, 604800000);
// Even better with a descriptive constant
const SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000;
cache.set('data', value, SEVEN_DAYS_MS);
function convertHoursToSeconds(hours) {
if (typeof hours !== 'number' || hours < 0) {
throw new Error('Hours must be a positive number');
}
return hours * 60 * 60;
}
💡 Pro Tip: Bookmark our time converter tool for instant conversions while coding. No need to break your flow!
Test your time conversion skills:
Use our time converter to check your answers!