Passing null as value will remove the header.
public setExpires ( DateTime $date = null ) : |
||
$date | DateTime | A \DateTime instance or null to remove the header |
return |
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $expiration_date = new DateTime(); $expiration_date->modify("+1 hour"); $response->setExpires($expiration_date); echo $response->getDate()->diff($expiration_date)->format("%h hours, %i minutes and %s seconds remaining");
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $expiration_date = time() + 86400; $response->setExpires($expiration_date); echo $response->getDate()->diff(new DateTime("@$expiration_date"))->format("%d days, %h hours, %i minutes and %s seconds remaining");In this example, we set the expiration date to be 24 hours in the future using a timestamp. We then use `getDate` to get the current time and calculate the remaining time until the expiration date before printing it to the screen. These examples use the Symfony\Component\HttpFoundation package library.
public setExpires ( DateTime $date = null ) : |
||
$date | DateTime | A \DateTime instance or null to remove the header |
return |