src/Mail.php
public static function formatDate($timestamp, $type = 'full_sort', $format = '', $timezone = null) {
    // Determine the format to use.
    switch ($type) {
      case 'date_sort':
        $format = 'Y-m-d';
        break;
      case 'date_long':
        $format = 'l, F j, Y';
        break;
      case 'date_med':
        $format = 'j M Y';
        break;
      case 'date_short':
        $format = 'n/d/Y';
        break;
      case 'time_sort':
        $format = 'H:i T';
        break;
      case 'time_long':
        $format = 'g:i:s A T';
        break;
      case 'time_med':
        $format = 'g:i:s A';
        break;
      case 'time_short':
        $format = 'g:i A';
        break;
      case 'full_sort':
        $format = 'Y-m-d H:i T';
        break;
      case 'full_long':
        $format = 'l, F j, Y g:i A T';
        break;
      case 'full_med':
        $format = 'j M Y g:i A T';
        break;
      case 'full_short':
        $format = 'n/d/Y g:i A T';
        break;
      case 'custom':
      default:
        break;
    }
    // Create a date object from the timestamp.
    try {
      $date = new \DateTime(gmdate('c', (int) $timestamp));
      if (isset($timezone)) {
        if (!is_object($timezone)) {
          $timezone = new \DateTimeZone($timezone);
        }
        $date->setTimezone($timezone);
      } else {
        $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
      }
    } catch (\Exception $e) {
      throw new \Exception("Error formatting date: $e");
    }
    return $date->format($format);
  }
public static function formatDate($timestamp, $type = 'full_sort', $format = '', $timezone = null) {
    // Determine the format to use.
    switch ($type) {
      case 'date_sort':
        $format = 'Y-m-d';
        break;
      case 'date_long':
        $format = 'l, F j, Y';
        break;
      case 'date_med':
        $format = 'j M Y';
        break;
      case 'date_short':
        $format = 'n/d/Y';
        break;
      case 'time_sort':
        $format = 'H:i T';
        break;
      case 'time_long':
        $format = 'g:i:s A T';
        break;
      case 'time_med':
        $format = 'g:i:s A';
        break;
      case 'time_short':
        $format = 'g:i A';
        break;
      case 'full_sort':
        $format = 'Y-m-d H:i T';
        break;
      case 'full_long':
        $format = 'l, F j, Y g:i A T';
        break;
      case 'full_med':
        $format = 'j M Y g:i A T';
        break;
      case 'full_short':
        $format = 'n/d/Y g:i A T';
        break;
      case 'custom':
      default:
        break;
    }
    // Create a date object from the timestamp.
    try {
      $date = new \DateTime(gmdate('c', (int) $timestamp));
      if (isset($timezone)) {
        if (!is_object($timezone)) {
          $timezone = new \DateTimeZone($timezone);
        }
        $date->setTimezone($timezone);
      } else {
        $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
      }
    } catch (\Exception $e) {
      throw new \Exception("Error formatting date: $e");
    }
    return $date->format($format);
  }
Format a date using the DateTime class.

$type can be any of the following:

- full_sort - Date and time, big endian and 24 hour format so it is sortable.
- full_long - Date and time, long format.
- full_med - Date and time, medium format.
- full_short - Date and time, short format.
- date_sort - Only the date, big endian so it is sortable.
- date_long - Only the date, long format.
- date_med - Only the date, medium format.
- date_short - Only the date, short format.
- time_sort - Only the time, 24 hour format so it is sortable.
- time_long - Only the time, long format.
- time_med - Only the time, medium format.
- time_short - Only the time, short format.
- custom - Use whatever is passed in $format.

@param int $timestamp The timestamp to format.
@param string $type The type of formatting to use.
@param string $format The format to use if type is 'custom'.
@param DateTimeZone|string|null $timezone The timezone to use for formatting. Defaults to date_default_timezone_get().
@return string The formatted date.