$dateString = '2021-07-20'; $dateTime = DateTime::createFromFormat('Y-m-d', $dateString); echo $dateTime->format('Y-m-d H:i:s');
$timestamp = 1626793183; $dateTime = new DateTime(); $dateTime->setTimestamp($timestamp); echo $dateTime->format('Y-m-d H:i:s');This code creates a new datetime object and sets its timestamp value to 1626793183 (the current Unix timestamp at the time of writing). It then formats the resulting datetime object to the desired output format. The Format ToDateTime function is part of the core PHP DateTime class, which is included in the standard PHP library.