$date = new DateTime(); $timestamp = $date->getTimestamp(); echo $timestamp; // output: 1629803236
$date = new DateTime('2021-09-01 15:30:00'); $timestamp = $date->getTimestamp(); echo $timestamp; // output: 1630549800In this example, we create a new DateTime object representing September 1, 2021, at 3:30 PM. We then call the getTimestamp method to retrieve the timestamp value and display it on the screen. Package Library: DateTime Class is built in and requires no additional package.