diff options
| author | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:45:38 +0100 |
|---|---|---|
| committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:45:38 +0100 |
| commit | 4ab365b110f2f1f2b736326b7059244a32115089 (patch) | |
| tree | c3c7c0219f728ade49a78c238c51cc0c8d06ebd6 /files/de/web/javascript/reference/errors/deprecated_tolocaleformat | |
| parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
| download | translated-content-4ab365b110f2f1f2b736326b7059244a32115089.tar.gz translated-content-4ab365b110f2f1f2b736326b7059244a32115089.tar.bz2 translated-content-4ab365b110f2f1f2b736326b7059244a32115089.zip | |
unslug de: move
Diffstat (limited to 'files/de/web/javascript/reference/errors/deprecated_tolocaleformat')
| -rw-r--r-- | files/de/web/javascript/reference/errors/deprecated_tolocaleformat/index.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/errors/deprecated_tolocaleformat/index.html b/files/de/web/javascript/reference/errors/deprecated_tolocaleformat/index.html new file mode 100644 index 0000000000..31cc81d9cc --- /dev/null +++ b/files/de/web/javascript/reference/errors/deprecated_tolocaleformat/index.html @@ -0,0 +1,90 @@ +--- +title: 'Warning: Date.prototype.toLocaleFormat is deprecated' +slug: Web/JavaScript/Reference/Fehler/Deprecated_toLocaleFormat +tags: + - JavaScript + - Warning +translation_of: Web/JavaScript/Reference/Errors/Deprecated_toLocaleFormat +--- +<div>{{jsSidebar("Errors")}}</div> + +<h2 id="Fehlermeldung">Fehlermeldung</h2> + +<pre class="syntaxbox">Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead +</pre> + +<h2 id="Fehlertyp">Fehlertyp</h2> + +<p>Warnung. JavaScript stoppt die ausführung nicht an.</p> + +<h2 id="Was_ist_falsch_gelaufen">Was ist falsch gelaufen?</h2> + +<p>Die nicht standardisierte Methode {{jsxref("Date.prototype.toLocaleFormat")}} ist veraltet und sollte nicht mehr benutzt werden. Sie benutzt einen Formatstring mit dem selben Format, wie dei der C Funktion <code>strftime()</code>. <strong>Diese Funktion ist seit Firefox 58+ nicht mehr vorhanden</strong>.</p> + +<h2 id="Beispiele">Beispiele</h2> + +<h3 id="Veraltete_Syntax">Veraltete Syntax</h3> + +<p>Die {{jsxref("Date.prototype.toLocaleFormat")}} Methode ist veraltet und wird entfernt werden (keine browserübergreifende Unterstützung, nur in Firefox verfügbar).</p> + +<pre class="brush: js example-bad">var today = new Date(); +var date = today.toLocaleFormat('%A, %e. %B %Y'); + +console.log(date); +// In German locale +// "Freitag, 10. März 2017"</pre> + +<h3 id="Alternative_Standardsyntax_mit_der_ECMAScript_Intl_API">Alternative Standardsyntax mit der ECMAScript Intl API</h3> + +<p>Der ECMA-402 Standard spezifiziert Standardobjekte und Methoden (ECMAScript Intl API), die sprachabhängige Datums- und Zeitformatierung erlauben (verfügbar in Chrome 24+, Firefox 29+, IE11+, Safari10+).</p> + +<p>Man kan jetzt die {{jsxref("Date.prototype.toLocaleDateString")}} Methode einsetzen, um einen Zeitpunkt zu formatieren.</p> + +<pre class="brush: js example-good">var today = new Date(); +var options = { weekday: 'long', year: 'numeric', + month: 'long', day: 'numeric' }; +var date = today.toLocaleDateString('de-DE', options); + +console.log(date); +// "Freitag, 10. März 2017" +</pre> + +<p>Oder man kann das {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} Objekt einsetzen, welches die meisten Berechnungen zwischenspeichert, so dass das Formatieren schneller ist. Dieses ist nützlich, wenn Zeitpunkte in einer Schleife formatiert werden.</p> + +<pre class="brush: js example-good">var options = { weekday: 'long', year: 'numeric', + month: 'long', day: 'numeric' }; +var dateFormatter = new Intl.DateTimeFormat('de-DE', options) + +var dates = [Date.UTC(2012, 11, 20, 3, 0, 0), + Date.UTC(2014, 04, 12, 8, 0, 0)]; + +dates.forEach(date => console.log(dateFormatter.format(date))); + +// "Donnerstag, 20. Dezember 2012" +// "Montag, 12. Mai 2014" +</pre> + +<h3 id="Alternative_Standardsyntax_mit_Date_Methoden">Alternative Standardsyntax mit Date Methoden</h3> + +<p>Das {{jsxref("Date")}} Objekt enthält einige Methoden, um einen Benutzerdefinierten Datumsstring zu erhalten.</p> + +<pre class="brush: js example-bad">(new Date()).toLocaleFormat("%Y%m%d"); +// "20170310" +</pre> + +<p>Dieses kan konvertiert werde:</p> + +<pre class="brush: js example-good">let now = new Date(); +let date = now.getFullYear() * 10000 + + (now.getMonth() + 1) * 100 + now.getDate(); + +console.log(date); +// "20170310"</pre> + +<h2 id="Siehe_auch">Siehe auch</h2> + +<ul> + <li>{{jsxref("Date.prototype.toLocaleFormat")}}</li> + <li>{{jsxref("Date.prototype.toLocaleDateString")}}</li> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> +</ul> |
