44 lines
1.6 KiB
HTML
44 lines
1.6 KiB
HTML
<!doctype html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Übung 05: FormatDate Fehler</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="container py-5">
|
|
<h1>Übung 05: FormatDate Fehler</h1>
|
|
</div>
|
|
</main>
|
|
<script>
|
|
'use strict';
|
|
function formatDate(date) {
|
|
const options = { year: 'numeric', month: 'long', day: 'numeric' };
|
|
const formatedDate = date.toLocaleDateString('en-EN', options); // statt undefined 'en-EN'
|
|
return formatedDate;
|
|
}
|
|
|
|
// use moment or luxon instead: https://momentjs.com/
|
|
|
|
const date = new Date();
|
|
const days = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnertag', 'Freitag', 'Samstag'];
|
|
|
|
const month = date.getMonth() + 1;
|
|
const day = date.getDate();
|
|
const weekDay = date.getDay();
|
|
const year = date.getFullYear();
|
|
|
|
const hh = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
|
|
const mm = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
|
|
const ss = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
|
|
|
|
console.log(`${day}.${month < 10 ? `0${month}` : month}.${year} ${hh}:${mm}:${ss}`);
|
|
|
|
console.log(formatDate(new Date('2023-05-31'))); // => 'May 31, 2023'
|
|
console.log(formatDate(new Date('2024-01-01'))); // => 'January 1, 2024'
|
|
</script>
|
|
</body>
|
|
</html>
|