Funzione PHP strtotime ()
Definizione e utilizzo
Il strtotime() la funzione accetta una stringa di data / ora, con valori di data / ora testuali e la analizza come un timestamp Unix.
Sintassi
strtotime($time) 
    Parametri
| Suor n | Parametro e descrizione | 
|---|---|
| 1 |   time(Mandatory) Questo valore rappresenta la stringa data / ora.  |  
      
| 2 |   now(Optional) Questo rappresenta un timestamp che viene utilizzato come base per il calcolo delle date relative ..  |  
      
Valori restituiti
La funzione strtotime () di PHP restituisce un valore di timestamp per la stringa di data specificata. In caso di errore, questa funzione restituisce il valore booleano false .
Versione PHP
Questa funzione è stata introdotta per la prima volta nella versione 4.0 di PHP e funziona con tutte le versioni successive.
Esempio
L'esempio seguente mostra l'utilizzo della funzione strtotime () :
<?php
   $str = strtotime("12 September 2009");
   print("Timestamp: ".$str); 
?> 
    Questo produrrà il seguente risultato:
Timestamp: 1252713600 
    Esempio
Se si passa "adesso" come parametro, questa funzione restituisce il timestamp corrente
<?php
   $str = strtotime("now");
   print("Timestamp: ".$str); 
?> 
    Questo produrrà il seguente risultato:
Timestamp: 1589369948 
    Esempio
Ora possiamo invocare questo metodo passando vari valori di data -
<?php
   print("Time stamp of 25 December 2019: ".strtotime("25 December 2019")."\n");
   print("Time stamp of +26 day: ".strtotime("+26 day")."\n");
   print("Time stamp of +3 week: ".strtotime("+3 week")."\n");
   print("Time stamp of +3 month 9 days 9 hours: ".strtotime("+3 month 9 days 9 hours")."\n");
   print("Time stamp of last Sunday: ".strtotime("last Sunday")."\n");
   print("Time stamp of next Friday: ".strtotime("next Friday")."\n");
?> 
    Questo produrrà il seguente output:
Time stamp of 25 December 2019: 1577232000
Time stamp of +26 day: 1591617718
Time stamp of +3 week: 1591185718
Time stamp of +3 month 9 days 9 hours: 1598130118
Time stamp of last Sunday: 1589068800
Time stamp of next Friday: 1589500800 
    Esempio
<?php
   $timestamp = strtotime( "February 15, 2015" );   
   print date( 'Y-m-d', $timestamp );
?> 
    Questo produrrà il seguente output:
2015-02-15 
                        