1
0
mirror of https://github.com/php/doc-it.git synced 2026-03-24 07:32:12 +01:00
Files
2022-11-14 23:56:18 +01:00

257 lines
8.2 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!-- EN-Revision: 0466dd93f73635c728c6c4707aaf5876692f1ef3 Maintainer: pastore Status: ready -->
<!-- CREDITS: curcio_it -->
<refentry xml:id="function.date" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>date</refname>
<refpurpose>Formatta un timestamp Unix</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>date</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>timestamp</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
Restituisce una stringa formattata in accordo con il formato della stringa data usando
l'intero <parameter>timestamp</parameter> dato (timestamp Unix) o l'orario corrente
se nessun timestamp è dato. In altre parole, <parameter>timestamp</parameter>
è opzionale e di default prende il valore di <function>time</function>.
</para>
<warning>
<para>
I timestamp Unix non gestiscono i fusi orari. Utilizzare la
classe <classname>DateTimeImmutable</classname>, e i suoi
metodi di formattazione <methodname>DateTimeInterface::format</methodname> per
formattare le informazioni data/ora con un fuso orario allegato.
</para>
</warning>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>format</parameter></term>
<listitem>
<para>
Formato accettato da <methodname>DateTimeInterface::format</methodname>.
</para>
</listitem>
</varlistentry>
&date.timestamp.description;
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Restituisce una stringa data formattata. Se viene utilizzato un valore non numerico per
<parameter>timestamp</parameter>, viene restituito &false; e viene
emesso un errore di livello <constant>E_WARNING</constant>.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
&date.timezone.errors.description;
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>timestamp</parameter> ora è nullable.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Esempi di <function>date</function></title>
<programlisting role="php">
<![CDATA[
<?php
// imposta il fuso orario di default da utilizzare.
date_default_timezone_set('UTC');
// Stampa qualcosa di simile a: Monday
echo date("l");
// Stampa qualcosa di simile a: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');
// Stampa: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
/* usa le costanti nel parametro format */
// stampa qualcosa di simile a: Wed, 25 Sep 2013 15:28:57 -0700
echo date(DATE_RFC2822);
// stampa qualcosa di simile a: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>
]]>
</programlisting>
</example>
</para>
<para>
È possibile evitare che un carattere riconosciuto nella stringa formato venga
espanso effettuando l'escape di esso anteponendo un backslash. Se il carattere con
un backslash è già una sequenza speciale, potrebbe essere necessario effettuare l'escape anche
del backslash.
<example>
<title>Effettuare l'escape dei caratteri in <function>date</function></title>
<programlisting role="php">
<![CDATA[
<?php
// stampa qualcosa di simile a: Wednesday the 15th
echo date('l \t\h\e jS');
?>
]]>
</programlisting>
</example>
</para>
<para>
È possibile utilizzare insieme <function>date</function> e
<function>mktime</function> per trovare date nel futuro
o nel passato.
<example>
<title>Esempio di <function>date</function> e di <function>mktime</function></title>
<programlisting role="php">
<![CDATA[
<?php
$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
$nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
?>
]]>
</programlisting>
</example>
<note>
<para>
Questo può essere più affidabile rispetto che semplicemente aggiungere o sottrarre il numero
di secondi in un giorno o in un mese ad un timestamp a causa dell'ora
legale.
</para>
</note>
</para>
<para>
Alcuni esempi della formattazione <function>date</function>. Notare che
si dovrebbe effettuare l'escape di qualsiasi altro carattere, come tutti quelli che
attualmente hanno un significato speciale produrranno risultati indesiderati, e
ad altri caratteri potrebbe essere assegnato un significato nelle versioni future di PHP.
Quando si effettua l'escape, assicurarsi di usare gli apici singoli in modo da evitare che i caratteri
come \n divengano nuove linee.
<example>
<title>Formattazione di <function>date</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Assumendo che oggi sia Il 10 Marzo, 2001, 5:16:18 pm, e che noi siamo nel
// Fuso Orario Mountain Standard Time (MST)
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>
]]>
</programlisting>
</example>
</para>
<para>
Per formattare le date in altri lingue,
può essere utilizzata <methodname>IntlDateFormatter::format</methodname>
al posto di <function>date</function>.
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
Per generare un timestamp da una stringa che rappresenta la data, si
può essere in grado di utilizzare <function>strtotime</function>. Inoltre, alcuni
database hanno delle funzioni per convertire i loro formati data in timestamp
(come la funzione <link xlink:href="&url.mysql.docs.date;">UNIX_TIMESTAMP</link>
di MySQL).
</para>
</note>
<tip>
<para>
Il timestamp dell'inizio della richiesta è disponibile in
<varname>$_SERVER['REQUEST_TIME']</varname>.
</para>
</tip>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>DateTimeImmutable::__construct</methodname></member>
<member><methodname>DateTimeInterface::format</methodname></member>
<member><function>gmdate</function></member>
<member><function>idate</function></member>
<member><function>getdate</function></member>
<member><function>getlastmod</function></member>
<member><function>mktime</function></member>
<member><methodname>IntlDateFormatter::format</methodname></member>
<member><function>time</function></member>
<member><link linkend="datetimeinterface.constants.types">Costanti di DateTime Predefinite</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->