JavaScript - Datum und Uhrzeit als Zeichenkette anzeigen

toLocaleString()


<div id="zeit"></div>


<
script>
var 
= new Date();
document.getElementById("zeit").textContent d.toLocaleString();
</
script>

Mehr unter: developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

DateTimeFormat()










<div id="deutsch"></div>


<
script>
const 
date = new Date();
document.getElementById("deutsch").textContent = new Intl.DateTimeFormat('de-DE', { dateStyle'full'timeStyle'long' }).format(date);
</
script>

<
div id="english"></div>

<
script>
const 
date2 = new Date();
document.getElementById("english").textContent = new Intl.DateTimeFormat('en-GB', { dateStyle'full'timeStyle'long' }).format(date2);
</
script>

<
div id="englishUS"></div>

<
script>
const 
date3 = new Date();
document.getElementById("englishUS").textContent = new Intl.DateTimeFormat('en-US', { dateStyle'full'timeStyle'long' }).format(date3);
</
script>

<div id="chinese"></div>

<
script>
const 
date4 = new Date();
document.getElementById("chinese").textContent = new Intl.DateTimeFormat('zh-SG', { dateStyle'full'timeStyle'long' }).format(date4);
</
script>

ISO 639-1 Standard-Sprachcodes
Sprache (Region)Code
Afrikaansaf
Albaniansq
Arabic (U.A.E.)ar-ae
Arabic (Bahrain) ar-bh
Arabic (Algeria)ar-dz
Arabic (Egypt)ar-eg
Arabic (Iraq)ar-iq
Arabic (Jordan)ar-jo
Arabic (Kuwait)ar-kw
Arabic (Lebanon)ar-lb
Arabic (Libya)ar-ly
Arabic (Morocco)ar-ma
Arabic (Oman)ar-om
Arabic (Qatar)ar-qa
Arabic (Saudi Arabia)ar-sa
Arabic (Syria)ar-sy
Arabic (Tunisia)ar-tn
Arabic (Yemen)ar-ye
Basqueeu
Belarusianbe
Bulgarianbg
Catalanca
Croatianhr
Chinese (PRC)zh-cn
Chinese (Hong Kong)zh-hk
Chinese (Singapore)zh-sg
Chinese (Taiwan)zh-tw
Czechcs
Danishda
Dutch (Standard)nl
Dutch (Belgium)nl-be
Englishen
English (Australia)en-au
English (Belize)en-bz
English (Canada)en-ca
English (United Kingdom)en-gb
English (Ireland)en-ie
English (Jamaica)en-jm
English (New Zealand)en-nz
English (Trinidad)en-tt
English (United States)en-us
English (South Africa)en-za
Estonianet
Farsifa
Finnishfi
Faeroesefo
French (Standard)fr
French (Belgium)fr-be
French (Canada)fr-ca
French (Switzerland)fr-ch
French (Luxembourg)fr-lu
Gaelic (Scotland)gd
German (Standard)de
German (Austria)de-at
German (Switzerland)de-ch
German (Liechtenstein)de-li
German (Luxembourg)de-lu
Greekel
Irishga
Hebrewhe
Hindihi
Hungarianhu
Indonesianid
Icelandicis
Italian (Standard)it
Italian (Switzerland)it-ch
Japaneseja
Koreanko
Korean (Johab)ko
Kurdishku
Lithuanianlt
Latvianlv
Macedonian (FYROM)mk
Malayalamml
Malaysianms
Maltesemt
Norwegian (Bokmål)nb
Norwegian (Nynorsk)nn
Norwegianno
Punjabipa
Polishpl
Portuguese (Portugal)pt
Portuguese (Brazil)pt-br
Rhaeto-Romanicrm
Romanianro
Romanian (Republic of Moldova)ro-md
Russianru
Russian (Republic of Moldova)ru-md
Sorbiansb
Slovaksk
Sloveniansl
Serbiansr
Spanish (Spain)es
Spanish (Argentina)es-ar
Spanish (Bolivia)es-bo
Spanish (Chile)es-cl
Spanish (Colombia)es-co
Spanish (Costa Rica)es-cr
Spanish (Dominican Republic)es-do
Spanish (Ecuador)es-ec
Spanish (Guatemala)es-gt
Spanish (Honduras)es-hn
Spanish (Mexico)es-mx
Spanish (Nicaragua)es-ni
Spanish (Panama)es-pa
Spanish (Peru)es-pe
Spanish (Puerto Rico)es-pr
Spanish (Paraguay)es-py
Spanish (El Salvador)es-sv
Spanish (Uruguay)es-uy
Spanish (Venezuela)es-ve
Swedishsv
Swedish (Finland)sv-fi
Thaith
Tswanatn
Turkishtr
Tsongats
Ukrainianuk
Urduur
Vendave
Vietnamesevi
Welshcy
Xhosaxh
Yiddishji
Zuluzu

Deutsches Datumsformat





<div id="datum1"></div>


<
script>
var 
date10 = new Date();
var 
options = { year'numeric'month'2-digit'day'2-digit' };
document.getElementById("datum1").textContent date10.toLocaleString('de-DE'options);
</
script>

<
div id="datum2"></div>

<
script>
var 
date11 = new Date();
var 
options = { year'numeric'month'numeric'day'numeric' };
document.getElementById("datum2").textContent date11.toLocaleString('de-DE'options);
</
script>

<
div id="datum3"></div>

<
script>
var 
date12 = new Date();
var 
options = { weekday'long'year'numeric'month'long'day'numeric' };
document.getElementById("datum3").textContent date12.toLocaleString('de-DE'options);
</
script>

<
div id="datum4"></div>

<
script>
var 
date13 = new Date();
var 
options = { weekday'short'year'numeric'month'short'day'numeric' };
document.getElementById("datum4").textContent date13.toLocaleString('de-DE'options);
</
script>

Ein bestimmtes Datum mit Uhrzeit setzen


<script>

// Ein bestimmtes Datum mit Uhrzeit setzen
const date = new Date(Date.UTC(202142130439738)); // Jahr, Monat, Tag, Stunden, Minuten, Millisekunden
</
script>

Mehr unter: developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat

Bausteine  Alle Anzeigen

Eine zufällige Auswahl von Bausteinen (Codeschnipsel) aus den Bereichen HTML, CSS, PHP, JavaScript und MySQL.

<strong> Stark betonter Inhalt

CSS - Fehleingaben in Formularen mit CSS hervorheben

PHP - Seitentitel der aktuellen Seite auslesen

JavaScript - Cookies setzen und löschen

MySQL - Eintrag in der Tabelle löschen