aboutsummaryrefslogtreecommitdiff
path: root/files/uk/web/javascript/reference/errors/deprecated_tolocaleformat
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/uk/web/javascript/reference/errors/deprecated_tolocaleformat
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/uk/web/javascript/reference/errors/deprecated_tolocaleformat')
-rw-r--r--files/uk/web/javascript/reference/errors/deprecated_tolocaleformat/index.html93
1 files changed, 93 insertions, 0 deletions
diff --git a/files/uk/web/javascript/reference/errors/deprecated_tolocaleformat/index.html b/files/uk/web/javascript/reference/errors/deprecated_tolocaleformat/index.html
new file mode 100644
index 0000000000..226aba7150
--- /dev/null
+++ b/files/uk/web/javascript/reference/errors/deprecated_tolocaleformat/index.html
@@ -0,0 +1,93 @@
+---
+title: 'Warning: Date.prototype.toLocaleFormat is deprecated'
+slug: Web/JavaScript/Reference/Errors/Deprecated_toLocaleFormat
+tags:
+ - Error
+ - JavaScript
+ - застереження
+translation_of: Web/JavaScript/Reference/Errors/Deprecated_toLocaleFormat
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<p>Застереження JavaScript "Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead" виникає, коли використовується нестандартний метод {{jsxref("Date.prototype.toLocaleFormat")}}.</p>
+
+<h2 id="Повідомлення">Повідомлення</h2>
+
+<pre class="syntaxbox notranslate">Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead
+</pre>
+
+<h2 id="Тип_помилки">Тип помилки</h2>
+
+<p>Застереження. Виконання JavaScript не буде зупинене.</p>
+
+<h2 id="Що_сталось">Що сталось?</h2>
+
+<p>Нестандартний метод {{jsxref("Date.prototype.toLocaleFormat")}} застарів та більше не рекомендований до використання. Він використовує рядок форматування в такому ж форматі, який очікується функцією <code>strftime()</code> у C. <strong>Функція більше недоступна у Firefox 58+</strong>.</p>
+
+<h2 id="Приклади">Приклади</h2>
+
+<h3 id="Застарілий_синтаксис">Застарілий синтаксис</h3>
+
+<p>Метод {{jsxref("Date.prototype.toLocaleFormat")}} застарів та буде прибраний (без кросбраузерної підтримки, доступний лише у Firefox).</p>
+
+<pre class="brush: js example-bad notranslate">var today = new Date();
+var date = today.toLocaleFormat('%A, %e. %B %Y');
+
+console.log(date);
+// У німецькій локалі
+// "Freitag, 10. März 2017"</pre>
+
+<h3 id="Альтернативний_стандартний_синтаксис_за_допомогою_ECMAScript_Intl_API">Альтернативний стандартний синтаксис за допомогою ECMAScript Intl API</h3>
+
+<p>Стандарт ECMA-402 (ECMAScript Intl API) визначає стандартні об'єкти та методи, які вможливлюють чутливе до мови форматування дати та часу (доступні у Chrome 24+, Firefox 29+, IE11+, Safari10+).</p>
+
+<p>Ви тепер можете або використати метод {{jsxref("Date.prototype.toLocaleDateString")}}, якщо ви бажаєте просто відформатувати одну дату.</p>
+
+<pre class="brush: js example-good notranslate">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>Або ви можете скористатись об'єктом {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}, який дозволяє кешувати об'єкт, в якому більшість обчислень вже зроблені, тому форматування відбувається швидко. Це корисно, якщо у вас є цикл дат для форматування.</p>
+
+<pre class="brush: js example-good notranslate">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 =&gt; console.log(dateFormatter.format(date)));
+
+// "Donnerstag, 20. Dezember 2012"
+// "Montag, 12. Mai 2014"
+</pre>
+
+<h3 id="Альтернативний_стандартний_синтаксис_з_використанням_методів_Date">Альтернативний стандартний синтаксис з використанням методів Date</h3>
+
+<p>Об'єкт {{jsxref("Date")}} пропонує декілька методів для створення налаштованого рядка дати.</p>
+
+<pre class="brush: js example-bad notranslate">(new Date()).toLocaleFormat("%Y%m%d");
+// "20170310"
+</pre>
+
+<p>Можна перетворити на:</p>
+
+<pre class="brush: js example-good notranslate">let now = new Date();
+let date = now.getFullYear() * 10000 +
+ (now.getMonth() + 1) * 100 + now.getDate();
+
+console.log(date);
+// "20170310"</pre>
+
+<h2 id="Див._також">Див. також</h2>
+
+<ul>
+ <li>{{jsxref("Date.prototype.toLocaleFormat")}}</li>
+ <li>{{jsxref("Date.prototype.toLocaleDateString")}}</li>
+ <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li>
+</ul>