@@Joergi
const tEarlier = new Date("2026-02-01"); const tLater = new Date("2026-05-01"); const tMillisecondsElapsed = tLater - tEarlier; const tELapsed = new Date(tMillisecondsElapsed);
Das ist Murks. tMillisecondsElapsed gibt keinen Zeitpunkt an, sondern eine Zeitdauer. Es ist unsinnig, eine Zeitdauer als Argument für den Date-Konstruktor zu verwenden.
zeigt hingegen als Ergebnis genau drei Monate an.
„Genau“ und „Monate“ widerspricht sich. Da Monate unterschiedlich lang sind, ist eine Angabe „x Monate“ niemals genau.
Und das ist richtig. Wie kann ich javascript dazu bringen, Monate wie z.B. den Februar korrekt zu berechnen?
Mit einer Bibliothek, die die Berechnung von Zeitdauern und deren Ausgabe in verschiedenen Formaten implementiert hat.
🖖 Live long and prosper
--
“In my home, the America I love, the America I've written about, that has been a beacon of hope and liberty for 250 years, is currently in the hands of a corrupt, incompetent and treasonous administration. Tonight, we ask all who believe in democracy and the best of our American spirit, to rise with us, raise your voices against authoritarianism, and let freedom reign.”
— Bruce Springsteen, Manchester 2025-05-14
“In my home, the America I love, the America I've written about, that has been a beacon of hope and liberty for 250 years, is currently in the hands of a corrupt, incompetent and treasonous administration. Tonight, we ask all who believe in democracy and the best of our American spirit, to rise with us, raise your voices against authoritarianism, and let freedom reign.”
— Bruce Springsteen, Manchester 2025-05-14