Chargement de l'outil...
components.privacyNotice.title components.privacyNotice.message
Saisissez les dates pour voir le résultat
👆 Saisissez les deux dates pour voir le calcul
Calculez précisément le temps écoulé entre deux dates avec différentes unités d'affichage. Cet outil prend en compte les années bissextiles, les fuseaux horaires et offre des calculs en jours ouvrés, heures de travail et bien plus encore.
Calcul basique entre deux dates avec résultat en différentes unités.
Calcul en excluant les weekends et jours fériés selon le pays sélectionné.
Âge exact avec années, mois et jours restants jusqu'au prochain anniversaire.
Calculs précis entre dates dans différents fuseaux horaires.
// Calculateur de différence entre dates avancé
class DateCalculator {
// Calcul de différence simple
static dateDifference(startDate, endDate, options = {}) {
const start = new Date(startDate);
const end = new Date(endDate);
if (start > end) {
throw new Error('La date de début doit être antérieure à la date de fin');
}
const diffMs = end.getTime() - start.getTime();
return {
milliseconds: diffMs,
seconds: Math.floor(diffMs / 1000),
minutes: Math.floor(diffMs / (1000 * 60)),
hours: Math.floor(diffMs / (1000 * 60 * 60)),
days: Math.floor(diffMs / (1000 * 60 * 60 * 24)),
weeks: Math.floor(diffMs / (1000 * 60 * 60 * 24 * 7)),
// Calcul précis années/mois/jours
precise: this.calculatePreciseDifference(start, end),
// Formatage lisible
readable: this.formatReadable(diffMs)
};
}
// Calcul précis avec années/mois/jours
static calculatePreciseDifference(startDate, endDate) {
let years = endDate.getFullYear() - startDate.getFullYear();
let months = endDate.getMonth() - startDate.getMonth();
let days = endDate.getDate() - startDate.getDate();
// Ajustements pour les calculs négatifs
if (days < 0) {
months--;
const lastDayOfPrevMonth = new Date(endDate.getFullYear(), endDate.getMonth(), 0).getDate();
days += lastDayOfPrevMonth;
}
if (months < 0) {
years--;
months += 12;
}
return { years, months, days };
}
// Calcul des jours ouvrés
static businessDays(startDate, endDate, excludeHolidays = true, country = 'FR') {
const start = new Date(startDate);
const end = new Date(endDate);
let businessDays = 0;
const current = new Date(start);
const holidays = excludeHolidays ? this.getHolidays(start.getFullYear(), country) : [];
while (current <= end) {
const dayOfWeek = current.getDay();
// Exclure weekends (0 = dimanche, 6 = samedi)
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
// Vérifier si c'est un jour férié
const currentDateStr = current.toISOString().split('T')[0];
if (!holidays.includes(currentDateStr)) {
businessDays++;
}
}
current.setDate(current.getDate() + 1);
}
return businessDays;
}
// Calcul d'âge précis
static calculateAge(birthDate, referenceDate = new Date()) {
const birth = new Date(birthDate);
const reference = new Date(referenceDate);
const age = this.calculatePreciseDifference(birth, reference);
// Calcul du prochain anniversaire
const nextBirthday = new Date(reference.getFullYear(), birth.getMonth(), birth.getDate());
if (nextBirthday < reference) {
nextBirthday.setFullYear(nextBirthday.getFullYear() + 1);
}
const daysToNextBirthday = Math.floor((nextBirthday - reference) / (1000 * 60 * 60 * 24));
const totalDaysLived = Math.floor((reference - birth) / (1000 * 60 * 60 * 24));
return {
...age,
totalDaysLived,
daysToNextBirthday,
nextBirthday: nextBirthday.toISOString().split('T')[0],
// Statistiques amusantes
totalHoursLived: totalDaysLived * 24,
totalMinutesLived: totalDaysLived * 24 * 60,
// Étapes de la vie
lifestage: this.getLifeStage(age.years)
};
}
// Jours fériés par pays (exemple France)
static getHolidays(year, country = 'FR') {
if (country === 'FR') {
return [
`${year}-01-01`, // Nouvel an
`${year}-05-01`, // Fête du travail
`${year}-05-08`, // Victoire 1945
`${year}-07-14`, // Fête nationale
`${year}-08-15`, // Assomption
`${year}-11-01`, // Toussaint
`${year}-11-11`, // Armistice
`${year}-12-25`, // Noël
// Pâques (calcul dynamique)
...this.getEasterDates(year)
];
}
return [];
}
// Calcul des dates de Pâques
static getEasterDates(year) {
const easter = this.calculateEaster(year);
const easterMonday = new Date(easter);
easterMonday.setDate(easter.getDate() + 1);
const ascension = new Date(easter);
ascension.setDate(easter.getDate() + 39);
const pentecost = new Date(easter);
pentecost.setDate(easter.getDate() + 50);
return [
easter.toISOString().split('T')[0],
easterMonday.toISOString().split('T')[0],
ascension.toISOString().split('T')[0],
pentecost.toISOString().split('T')[0]
];
}
// Algorithme de calcul de Pâques
static calculateEaster(year) {
const a = year % 19;
const b = Math.floor(year / 100);
const c = year % 100;
const d = Math.floor(b / 4);
const e = b % 4;
const f = Math.floor((b + 8) / 25);
const g = Math.floor((b - f + 1) / 3);
const h = (19 * a + b - d - g + 15) % 30;
const i = Math.floor(c / 4);
const k = c % 4;
const l = (32 + 2 * e + 2 * i - h - k) % 7;
const m = Math.floor((a + 11 * h + 22 * l) / 451);
const month = Math.floor((h + l - 7 * m + 114) / 31);
const day = ((h + l - 7 * m + 114) % 31) + 1;
return new Date(year, month - 1, day);
}
// Étape de la vie selon l'âge
static getLifeStage(years) {
if (years < 2) return 'Bébé';
if (years < 6) return 'Petite enfance';
if (years < 12) return 'Enfance';
if (years < 18) return 'Adolescence';
if (years < 30) return 'Jeune adulte';
if (years < 50) return 'Adulte';
if (years < 65) return 'Adulte mature';
return 'Senior';
}
// Formatage lisible
static formatReadable(milliseconds) {
const units = [
{ name: 'année', value: 1000 * 60 * 60 * 24 * 365.25 },
{ name: 'mois', value: 1000 * 60 * 60 * 24 * 30.44 },
{ name: 'jour', value: 1000 * 60 * 60 * 24 },
{ name: 'heure', value: 1000 * 60 * 60 },
{ name: 'minute', value: 1000 * 60 },
{ name: 'seconde', value: 1000 }
];
for (const unit of units) {
const value = Math.floor(milliseconds / unit.value);
if (value >= 1) {
const remainder = milliseconds % unit.value;
const nextUnit = units[units.indexOf(unit) + 1];
if (remainder > 0 && nextUnit) {
const nextValue = Math.floor(remainder / nextUnit.value);
if (nextValue >= 1) {
return `${value} ${unit.name}${value > 1 ? 's' : ''} et ${nextValue} ${nextUnit.name}${nextValue > 1 ? 's' : ''}`;
}
}
return `${value} ${unit.name}${value > 1 ? 's' : ''}`;
}
}
return 'Moins d\'une seconde';
}
}
// Exemples d'utilisation
const startDate = '2024-01-01';
const endDate = '2024-03-15';components.outilPage.suggestion.description