PHP date() & strtotime()

Riferimento interattivo: testa le stringhe di formato, consulta i parametri e prova le espressioni strtotime().

date(" ")
{{ dateResult }}
<?php echo date("{{ dateFormat }}"); ?>
{{ __t('th_character') }} {{ __t('th_description') }} {{ __t('th_example') }}
strtotime(" ")
{{ strtotimeResult.timestamp }}
{{ strtotimeResult.formatted }}
{{ strtotimeResult.relative }}
{{ strtotimePhpCode }}
{{ __t('alert_expression_not_recognized') }}
{{ cat.title }}
{{ __t('th_expression') }} {{ __t('th_description') }} {{ __t('label_result') }}
{{ ref.expr }} {{ ref.desc }} {{ getStrtotimeExample(ref.expr) }}

PHP date() — Parametri di formato

La funzione date(string $format, ?int $timestamp = null) formatta un timestamp Unix o l'ora corrente in una stringa leggibile. La stringa di formato è composta da segnaposto come Y (anno a quattro cifre), m (mese con zero iniziale), d (giorno) o H:i:s (ore:minuti:secondi in formato 24h).

PHP strtotime() — Espressioni temporali relative

strtotime(string $datetime, ?int $baseTimestamp = null) converte descrizioni testuali in inglese in timestamp Unix. Input tipici: "now", "+1 day", "next monday", "first day of next month", "last day of december 2025". La funzione è estremamente flessibile e comprende anche espressioni combinate come "+2 weeks 3 days".

Formati comuni

  • date("Y-m-d") — Data ISO: 2025-03-15
  • date("d.m.Y") — Formato tedesco: 15.03.2025
  • date("Y-m-d H:i:s") — MySQL Datetime
  • date("c") — ISO 8601: 2025-03-15T14:30:00+01:00
  • date("r") — RFC 2822: Sat, 15 Mar 2025 14:30:00 +0100
  • date("U") — Timestamp Unix